C Shell script in Linux: writing to text file

Posted on 2011-10-28
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?
Question by:wademi
    LVL 68

    Expert Comment

    date >> myfile.log

    LVL 31

    Expert Comment

    date > myfile.log

    Author Comment

    How would I append string? example " File copy started"


    Oct 28 4:55pm File copy started
    LVL 31

    Expert Comment

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

    Accepted Solution

    echo `date` "File copy started" >> myfile.log
    LVL 31

    Expert Comment

    echo `date`" File copy started"
    LVL 48

    Expert Comment

    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


    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    I have been running these systems for a few years now and I am just very happy with them.   I just wanted to share the manual that I have created for upgrades and other things.  Oooh yes! FreeBSD makes me happy (as a server), no maintenance and I al…
    Have you ever been frustrated by having to click seven times in order to retrieve a small bit of information from the web, always the same seven clicks, scrolling down and down until you reach your target? When you know the benefits of the command l…
    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.

    728 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

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now