Hi,
I am trying to execute a Shell script file.
The file has the following commands.
#Return today's log file
LOG_DATE=`date +%d_%b_%Y`.log
echo $LOG_DATE
#Return last modified date of the Log File
FILE_MOD_DATE=`date -r $LOG_DATE`
echo $FILE_MOD_DATE
If I execute the commands individually I get
09_Mar_2009.log
Mon Mar 9 14:50:26 IST 2009
If I execute as a file the output does not contain first letter.
9_Mar_2009.log
on Mar 9 14:50:26 IST 2009
What could be the reason and how to resolve the Issue?
I just tried your script - it worked perfectly for me. Both from the command line and in a script.
Are you running a console window or X?
Whats that? console window? X?
I am new to Unix and Cygwin.
rikxik
March 10, 2009, 5:39am
4
I tried in cygwin and the step by step output matches with script output:
[/cygdrive/c/temp] > touch `date +%d_%b_%Y`.log
[/cygdrive/c/temp] >
[/cygdrive/c/temp] > ls -l `date +%d_%b_%Y`.log
-rw-r--r-- 1 1273699 soumen 0 Mar 10 17:19 10_Mar_2009.log
[/cygdrive/c/temp] > LOG_DATE=`date +%d_%b_%Y`.log
[/cygdrive/c/temp] > echo $LOG_DATE
10_Mar_2009.log
[/cygdrive/c/temp] > FILE_MOD_DATE=`date -r $LOG_DATE`
[/cygdrive/c/temp] > echo $FILE_MOD_DATE
Tue Mar 10 17:19:53 MPST 2009
vs.
[/cygdrive/c/temp] > cat as_a_file
#Return today's log file
LOG_DATE=`date +%d_%b_%Y`.log
echo $LOG_DATE
#Return last modified date of the Log File
FILE_MOD_DATE=`date -r $LOG_DATE`
echo $FILE_MOD_DATE
[/cygdrive/c/temp] > as_a_file
10_Mar_2009.log
Tue Mar 10 17:19:53 MPST 2009
Hi,
Few Clarifications required.
In your code, to execute a file you have just specified the filename.
I couldn't do that. I use the Command sh filename.ksh
Is that rt?
Further, Is anything wrong with my Cygwin installation?
What about just this where filename.ksh is the name of the script you created:
./filename.ksh
or this
sh; ./filename.ksh
the command sh invokes the sh shell... it looks like you are trying to use 2 seperate commands on the same line.
Also, its good practice when writing shell scripts to say what kind of script they are by using a line similar to this as your first line:
#!/bin/ksh
rikxik
March 10, 2009, 9:59pm
7
anneanne:
Hi,
Few Clarifications required.
In your code, to execute a file you have just specified the filename.
I couldn't do that. I use the Command sh filename.ksh
Is that rt?
Further, Is anything wrong with my Cygwin installation?
I simply created the script in cygwin using vi, gave execute permissions (chmod 755 as_a_file) and then invoked it just by its name (no ksh/sh put). By default it picks /bin/bash for me (you can check yours by doing "echo $SHELL" at cygwin prompt).