Results 1 to 4 of 4
Hi,
I need some help with a shell script I am working on. I am not too familiar with it and I am editing someone else's code.
I dont necessarily ...
- 09-26-2007 #1Just Joined!
- Join Date
- Sep 2007
- Posts
- 3
I need shell script help
Hi,
I need some help with a shell script I am working on. I am not too familiar with it and I am editing someone else's code.
I dont necessarily want the answers to the problem as much as I want to know what is going on and why are the errors being triggered. I did google searches and they helped a little, but they seemed to apply to other situations.
I have copied and pasted the shell script below:
I am using Cygwin to compile this. This is the printout I am receiving:Code:#!/bin/sh # =========================== # get filename and region id # =========================== cd /bwflatfiles/"Load Status Controls"/ pwd filename='ls ??_status.txt' region='ls ??_status.txt cut -c 1-2' echo $region $filename # =============================== # get load status for the region # =============================== grep '0' $filename # look for a load status of 0 zero exitstatus=$? echo $exitstatus # =============================== # get date and time # =============================== d='date +%Y%m%d%H%M%S' # =============================== # Interrogate status # =============================== if [ ${exitstatus} = "0" ] # means grep found a 0 (zero) in the file (Green) then status="_green" load="_BW_load_is_complete" if [ -f bwload_fail$region ] then outfile="$region$load$status$d.txt" cat "BW Data Load Successful" > $outfile echo "load successful...ftping to success folder" ftp -ni servername <<-ENDFTP 2>&1 user "user" Bi,web01 cd BW lcd /bwflatfiles/Load Status Controls put $outfile ENDFTP rm -f bwload_fail$region rm $filename rm $outfile else echo "do nothing...success" rm $filename exit fi else status="_red" load="_BW_load_has_delayed" if [ -f bwload_fail$region ] then echo "do nothing...notice already sent" rm $filename exit else outfile="$region$load$status$d.txt" cat "BW Data Load Delayed" > $outfile echo "load failed...ftping to fail folder" ftp -ni servername <<-ENDFTP 2>&1 user "user" Bi,web01 cd BW lcd /bwflatfiles/Load Status Controls put $outfile ENDFTP date > bwload_fail$region rm $filename rm $outfile fi fi
Code:+ cd '/bwflatfiles/Load Status Controls/' lmon_region.sh: line 8: cd: /bwflatfiles/Load Status Controls/: No such file or directory + pwd /cygdrive/c/New + filename='ls ??_status.txt' + region='ls ??_status.txt cut -c 1-2' + echo ls '??_status.txt' cut -c 1-2 ls '??_status.txt' ls ??_status.txt cut -c 1-2 ls ??_status.txt + grep 0 ls '??_status.txt' grep: ls: No such file or directory grep: ??_status.txt: No such file or directory + exitstatus=2 + echo 2 2 + d='date +%Y%m%d%H%M%S' + '[' 2 = 0 ']' + status=_red + load=_BW_load_has_delayed + '[' -f bwload_faills '??_status.txt' cut -c 1-2 ']' lmon_region.sh: line 55: [: too many arguments + outfile='ls ??_status.txt cut -c 1-2_BW_load_has_delayed_reddate +%Y%m%d%H%M %S.txt' + cat 'BW Data Load Delayed' lmon_region.sh: line 63: $outfile: ambiguous redirect + echo 'load failed...ftping to fail folder' load failed...ftping to fail folder + ftp -ni servername lcd local directory. ls: File not found + date lmon_region.sh: line 71: bwload_fail$region: ambiguous redirect + rm ls '??_status.txt' rm: cannot remove `ls': No such file or directory rm: cannot remove `??_status.txt': No such file or directory + rm ls '??_status.txt' cut -c 1-2_BW_load_has_delayed_reddate +%Y%m%d%H%M%S.txt rm: invalid option -- c Try `rm --help' for more information.
My questions:
for the ambiguous redirects, is my target multiple targets and it is giving me this error?
For too many arguments: If I use single quotes, the message does not come up. Will this change what I want line 55 (if [ -f bwload_fail$region ]) to do?
For the "invalid option" at the bottom, I think the syntax is correct for region='ls ??_status.txt cut -c 1-2'. That's what it is referring to, right? Anyway, why is it giving me this message?
Note: This script is on my local drive and I am not running it on the server so that is why the folders do not exist. I am just trying to get the syntax down correct.
Thanks
- 09-26-2007 #2Just Joined!
- Join Date
- Aug 2007
- Posts
- 37
The problems all seem to stem from lines 10 and 11 of your script:
I suppose you meant to use backticks here?, and also you need to pipe the output of 'ls ??_status.txt' to 'cut -c 1-2'. Try altering those two lines and see if all the other error messages go away.Code:filename='ls ??_status.txt' region='ls ??_status.txt cut -c 1-2'
(p.s. your code would be *much* easier to read and debug if you indented it correctly.)Code:filename=`ls ??_status.txt` region=`ls ??_status.txt | cut -c 1-2`
- 09-26-2007 #3Just Joined!
- Join Date
- Sep 2007
- Posts
- 3
OMG I think you did it!
Obviously, I dont know my unix code very well. Can you recommend some good free online tutorials?
- 09-28-2007 #4Just Joined!
- Join Date
- Sep 2007
- Posts
- 3
Ok, MOST errors are cleared.
There is one error that is popping up.
it is referring to this line of code:Code:lmon_region.sh: line 31: [: too many arguments
There are 2 locations in that statement, I got that much. Why wont this code take?Code:if [ -f bwload_fail$region ]
Would it suit better this way:Thanks againCode:if [ -f '$bwload_fail$region' ]


Reply With Quote