Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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
#*********************************************************************
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
provided you have tcsh installed and it is installed in /bin. Some systems put it under /usr/bin, others do not install it by default. Check using which tcsh.
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}
do
<your code here>
done
Maybe I'm missing something, but to me the choice of a loop is not related to the if/then/else construct or the grep command. Indeed, it is not related to any command within the loop. The choice is based on the logic of the entire construct. Since the foreach/end construct in tcsh loops over the word list, the equivalent will be a for loop over the same word list.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.