Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

C Shell script in Linux: writing to text file

Posted on 2011-10-28
7
Medium Priority
?
301 Views
Last Modified: 2012-08-13
I am trying to log activities from my C Shell script in Linux.
How do I ouput the date to a log file. Say for example my logfile name is myfile.log
How would I write the current date and time to the text file?
0
Comment
Question by:wademi
7 Comments
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 37047745
date >> myfile.log

wmp
0
 
LVL 31

Expert Comment

by:farzanj
ID: 37047753
date > myfile.log
0
 

Author Comment

by:wademi
ID: 37047779
How would I append string? example " File copy started"

Example:

Oct 28 4:55pm File copy started
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 31

Expert Comment

by:farzanj
ID: 37047796
set D=`date`
 echo $D" File copy started"
Fri Oct 28 21:16:00 UTC 2011 File copy started
0
 
LVL 68

Accepted Solution

by:
woolmilkporc earned 2000 total points
ID: 37047798
echo `date` "File copy started" >> myfile.log
0
 
LVL 31

Expert Comment

by:farzanj
ID: 37047804
echo `date`" File copy started"
0
 
LVL 48

Expert Comment

by:Tintin
ID: 37048188
No echo needed and if you want it in the date/time format you specified, then do


date "+%b %d %H:%M%p file copy started" >>myfile.log

Open in new window

0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I promised to write further about my project, and here I am.  First, I needed to setup the Primary Server.  You can read how in this article: Setup FreeBSD Server with full HDD encryption (http://www.experts-exchange.com/OS/Unix/BSD/FreeBSD/A_3660-S…
FreeBSD on EC2 FreeBSD (https://www.freebsd.org) is a robust Unix-like operating system that has been around for many years. FreeBSD is available on Amazon EC2 through Amazon Machine Images (AMIs) provided by FreeBSD developer and security office…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Suggested Courses

572 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question