Hi.. Need to ask you a simple script question, I used the date command to get the yesterday web log file using the following command echo ex`date -d yesterday +%y%m%d.log` in Linux. I want to create a simple script to cat /home/IT/ex060530.log > kr.log using the following script but it is not working. May I know how do I put the output of echo ex`date -d yesterday +%y%m%d.log into cat /home/IT/xxxx > kr.log ?
[root@w2 krweblog3]# echo ex`date -d yesterday +%y%m%d.log` ex060530.log
[root@w2 krweblog3]# vi krweblog.sh
#!/bin/sh # KRWEBLOG3= echo ex`date -d yesterday +%y%m%d.log` cat /home/IT/$KRWEBLOG3 > kr.log
__________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
M E Fieu wrote:
Hi.. Need to ask you a simple script question, I used the date command to get the yesterday web log file using the following command echo ex`date -d yesterday +%y%m%d.log` in Linux. I want to create a simple script to cat /home/IT/ex060530.log> kr.log using the following script but it is not working. May I know how do I put the output of echo ex`date -d yesterday +%y%m%d.log into cat /home/IT/xxxx> kr.log ?
[root@w2 krweblog3]# echo ex`date -d yesterday +%y%m%d.log` ex060530.log
[root@w2 krweblog3]# vi krweblog.sh
#!/bin/sh # KRWEBLOG3= echo ex`date -d yesterday +%y%m%d.log` cat /home/IT/$KRWEBLOG3> kr.log
Get rid of the echo, it's not needed.
KRWEBLOG3="ex`date -d yesterday +%y%m%d.log`
If you ever do have to run a few commands to create a variable, you can use bash's command substitution to nest commands. Instead of using backquotes (`command`), you use $(command).
KRWEBLOG3=$(echo ex$(date -d yesterday +%y%m%d.log))
See the section on Expansion in the bash man page for more details.
- -- Todd OpenPGP -> KeyID: 0xD654075A | URL: www.pobox.com/~tmz/pgp ====================================================================== A free society is one where it is safe to be unpopular. -- Adlai Stevenson
M E Fieu wrote:
Hi.. Need to ask you a simple script question, I used the date command to get the yesterday web log file using the following command echo ex`date -d yesterday +%y%m%d.log` in Linux. I want to create a simple script to cat /home/IT/ex060530.log > kr.log using the following script but it is not working. May I know how do I put the output of echo ex`date -d yesterday +%y%m%d.log into cat /home/IT/xxxx > kr.log ?
[root@w2 krweblog3]# echo ex`date -d yesterday +%y%m%d.log` ex060530.log
[root@w2 krweblog3]# vi krweblog.sh
#!/bin/sh # KRWEBLOG3= echo ex`date -d yesterday +%y%m%d.log` cat /home/IT/$KRWEBLOG3 > kr.log
For thing like this, I like to use something like:
KRWEBLOG=$(date -d yesterday +ex%y%m%d.log) cat /home/IT/$KRWEBLOG3 > kr.log
KRWEBLOG will have the value of ex060530.log if I ran it now on my system. Enclosing a command inside $() returns the output of the command. You could also use: KRWEBLOG=`date -d yesterday +ex%y%m%d.log` but I find the $() format easyer to read.
Mikkel