LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This 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


Reply
  Search this Thread
Old 01-14-2009, 05:17 PM   #1
cat555
LQ Newbie
 
Registered: Nov 2008
Posts: 12

Rep: Reputation: 0
Question 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,
 
Old 01-14-2009, 05:39 PM   #2
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
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.

Last edited by colucix; 01-14-2009 at 05:40 PM.
 
Old 01-14-2009, 05:39 PM   #3
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
Sorry... erroneous double posting...

Last edited by colucix; 01-14-2009 at 05:41 PM.
 
Old 01-20-2009, 05:43 PM   #4
cat555
LQ Newbie
 
Registered: Nov 2008
Posts: 12

Original Poster
Rep: Reputation: 0
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?
 
Old 01-20-2009, 05:58 PM   #5
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
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?

Last edited by colucix; 01-20-2009 at 05:59 PM.
 
Old 01-20-2009, 06:29 PM   #6
cat555
LQ Newbie
 
Registered: Nov 2008
Posts: 12

Original Poster
Rep: Reputation: 0
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.
 
Old 01-20-2009, 08:18 PM   #7
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,240

Rep: Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324
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/
 
Old 01-22-2009, 03:33 PM   #8
cat555
LQ Newbie
 
Registered: Nov 2008
Posts: 12

Original Poster
Rep: Reputation: 0
Thaks for your suggestion!
I am using bash, and a for - if then else and have it pretty much running now.
Thanks!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Problems with shell scripting and sed Uzelth Programming 5 04-13-2008 07:21 PM
Shell scripting: Doing MySQL Dump base on date Swakoo Linux - General 2 09-21-2005 11:23 PM
Linux Shell Scripting yaadhav Linux - Newbie 4 08-20-2005 04:05 PM
Shell scripting Problems! herve2001 Linux - General 7 02-26-2005 09:57 PM
Shell Scripting problems (newbie) yawgmoth81 Programming 11 02-24-2003 03:31 AM


All times are GMT -5. The time now is 08:49 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration