shell scripting on linux / mysql problems
Hi,
I have written a shell script for oracle on linux that does a df for specific files, and then will display the size, Avail, % used and the difference from yesterday to today. I have been asked to place it on some MySql databases that run onn linux also, but when I try to run them I am getting some bizar errors. Not knowing anything about MySql, I am in need of some help. Here is a portion of the script and the errors I get just for those lines. Help please, or even if you can recommend a book that deals with shell scripting on mysql? set F_SYSTEMS= ( /mysql ) set OUTFILE=${WORK_DIR}/files.out set TMPFILE=${WORK_DIR}/temp set WRKFILE=${WORK_DIR}/files.txt set ARCHFILE=${WORK_DIR}/fs_yesterday.out #********************************************************************* #* Loop through the list of partitions #********************************************************************* printf '%12s %79s\n' "(KB)" "DAY TO DAY">> ${OUTFILE} printf '%12s %11s %11s %6s %-34s %10s\n' "SIZE" "USED" "AVAIL" "%USED" "MOUNTED" "DELTA">> ${OUTFILE} foreach PARTITION (${F_SYSTEMS}) df -k ${PARTITION} > ${WRKFILE} grep -v Filesystem ${WRKFILE} | grep % | tr -s "" " " | sed -e 's/^ //g' | sed -e 's/^ //g' > ${TMPFILE} if (`cut -c1 ${TMPFILE}` == '/') then set SIZ=`cut -d" " -f2 ${TMPFILE}` set USD=`cut -d" " -f3 ${TMPFILE}` set AVAIL=`cut -d" " -f4 ${TMPFILE}` set PCT=`cut -d" " -f5 ${TMPFILE} | sed -e 's/%//'` set MNTD=`cut -d" " -f6 ${TMPFILE}` else : ./my.csh ./my.csh: line 21: syntax error near unexpected token `(' ./my.csh: line 21: `set F_SYSTEMS=( /mysql )' ./my.csh: line 32: $OUTFILE: ambiguous redirect ./my.csh: line 33: ${OUTFILE}: ambiguous redirect ./my.csh: line 35: syntax error near unexpected token `(' ./my.csh: line 35: `foreach PARTITION (${F_SYSTEMS})' ./my.csh: line 35: foreach: command not found Does anyone have a clue what these errors are wanting? I have tried going through and changing, for example, set F_SYSTEMS=( /mysql ) to F_SYSTEMS= /mysql and $(OUTFILE) to OUTFILE but when it tells me that 'foreach: command not found' I am stymied as to what to do nex. Any help will be greatly appreciated, thanks, |
You're trying to execute a C-shell script using a Bourne Shell. Be sure to put the correct sha-bang at the beginning of the script. For example:
Code:
#!/bin/tcsh |
Sorry... erroneous double posting...
|
I am now trying to convert a csh script to bash. I can't use the foreach with an if, then else in bash. If you are using data from a grep statement, which loop would work better with a if, then, else inside it?
|
Have you tried a simple for loop like the following?
Code:
for PARTITION in ${F_SYSTEMS} Just out of curiosity, what about using the correct sha-bang #!/bin/tcsh (or #!/usr/bin/tcsh depending on your installation) at the beginning of the script? Does it work as expected or did you encounter other problems? |
The boxes do not have tcsh. The choice is csh or bash. And for whatever reason the csh is not working for me. This script worked on oracle databases on both unix and linux. I now have to make them work on mysql databases on linux and even though the system says there is a /bin/csh and /bin/tcsh I am getting such crazy errors, that I do not know how to translate or fix. It was suggested to me that I write it in bash, so that is what I was attempting.
Sorry if I sound a bit frustrated, it is only because I am. |
Its definitely a shell issue. Nothing whatsoever to do with the DB.
Try reading these bash guides and all will become clear: http://tldp.org/LDP/Bash-Beginners-G...tml/index.html http://www.tldp.org/LDP/abs/html/ |
Thaks for your suggestion!
I am using bash, and a for - if then else and have it pretty much running now. Thanks! |
All times are GMT -5. The time now is 04:37 PM. |