Script syntax help


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script syntax help
# 1  
Old 02-02-2015
Script syntax help

Code:
#!/bin/bash
if [ -z "$1" ] ; then
echo "Lipsa IP";
exit;
fi
i=1
ip=$1
while [ $i -le `wc -l pass_file | awk '{print $1}'` ] ; do
if [ -n "$ip" ]; then
rand=`head -$i pass_file | tail -1`
user=`echo $rand | awk '{print $1}'`
pass=`echo $rand | awk '{print $2}'`

CMD=`ps -eaf | grep -c mysql`

if [ "$CMD" -lt "50" ]; then
./mysql $ip $user $pass &
else
        sleep 15
fi
    i=`expr $i + 1`

done

Output is
Code:
./sql2: line 23: syntax error near unexpected token `done'
./sql2: line 23: `done'

Where i'm failing?
# 2  
Old 02-02-2015
Hi,
Second 'if" is not close (fi is missing).

Regards.
This User Gave Thanks to disedorgue For This Post:
# 3  
Old 02-02-2015
Can you please fix it and re-post the corrected version please?
# 4  
Old 02-02-2015
I don't know this 'if' must doing, so I don't know where 'if' clause must terminate.
# 5  
Old 02-02-2015
Tried to limit the script without passing 50 processes but I ruined it.

Can you please fix it without this part

Code:
CMD=`ps -eaf | grep -c mysql`

if [ "$CMD" -lt "50" ]; then
./mysql $ip $user $pass &
else
        sleep 15
fi
    i=`expr $i + 1`

done

---------- Post updated at 07:35 AM ---------- Previous update was at 07:30 AM ----------

Code:
#!/bin/bash
if [ -z "$1" ] ; then
echo "Lipsa IP";
exit;
fi
i=1
ip=$1
while [ $i -le `wc -l pass_file | awk '{print $1}'` ] ; do
if [ -n "$ip" ]; then
rand=`head -$i pass_file | tail -1`
user=`echo $rand | awk '{print $1}'`
pass=`echo $rand | awk '{print $2}'`
fi
./mysql $ip $user $pass &
done

This is wrong too as the script is entering an endless loop and its still bad for me..
# 6  
Old 02-02-2015
And , if you add i=`expr $i + 1` just before done ?
# 7  
Old 02-02-2015
Trying to understand your script I figure that you iterate through the pass_file line by line, read user and pass from it and run "mysql" in background with these two parameters, limiting the number of concurrent background processes. Some questions:
- do you really need to evaluate the file size in every loop? Does it change?
- do you really need to check $ip existence in every loop (even more as you check $1 in the second line and exit if NULL)
- do you really want to skip the actual user/pass if the process count is greater than your limit (and just sleep 15)?

Consider changing your script to sth like (untested, just for pointing you in some direction):
Code:
while read user pass REST
  do while [[ $(ps -eaf | grep -c [m]ysql) -gt 50 ]]
           do sleep 15
           done      
     ./mysql $ip $user $pass &
  done < pass_file

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help with syntax of Python script

I added some fields to some existing code, and all was well. Just added a few more, and BAM. I've looked this over forever, but being a newbie to Python, I see NOTHING. The code generates syslog messages, and the new fields were added around "rtp_lapse*" . Any clues??? #!/usr/bin/python ... (4 Replies)
Discussion started by: gmark99
4 Replies

2. UNIX for Dummies Questions & Answers

Syntax Error Script

Hi guys i'd like to show you this code of my script, where i couldn't find this error " #! /bin/bash #copiabin.sh: copia todos los archivos ejecutables a bin if then mkdir $HOME/bin fi # copia de archivos y contador N N=0 for ARCH in * do if # Si el archivo es... (9 Replies)
Discussion started by: Newer
9 Replies

3. Shell Programming and Scripting

Syntax error calling TCL script from shell script

hello everyone i am beginner on shell scripting .and i am working on my project work on ad hoc network i wrote a batch (.sh) to do a looping and execute a tcl script i wrote before in each iteration ..but i got this problem " syntax error near unexpected token `('... (1 Reply)
Discussion started by: marcoss90
1 Replies

4. Shell Programming and Scripting

sftp syntax in script

I am have FTP syntax like below in my bash shell script ftp -n <<END open $Server user $FtpUser $FtpPwd cd $FtpPath binary put $Filename.gz bye END Now I wanted to change this into SFTP. I tried... (4 Replies)
Discussion started by: sbmk_design
4 Replies

5. Shell Programming and Scripting

Syntax error in script

Hey guys keep having problems with the below script syntax error near unpexpected token '0' exit 0 I have two directorys backups and Usr in the usr i have sub dir's wp,ss,pic which i would like to back up (copy those directorys to the backups directory) with user acknowledgement from command line.... (2 Replies)
Discussion started by: Spartukus
2 Replies

6. Shell Programming and Scripting

Syntax error with a script

Hi I not sure what is wrong with my script... when I try to run it I get the follow error: "remove: syntax error at line 77: `end of file' unexpected" Thanks in advance for any help. ans=y while do while : do echo "Please enter a name that you... (3 Replies)
Discussion started by: simpsonjr
3 Replies

7. Shell Programming and Scripting

syntax error on script

Hello all, I am trying to write a little script to create a file and I keep getting the below error and cant see where my syntax mistake(s) is. please help... the script: FILE="/u/e477059/Unix_Machines/LISTS" for X in `cat ${FILE}/list` do ssh $X "echo $X; cd /var/tmp; ... (2 Replies)
Discussion started by: rookieuxixsa
2 Replies

8. Shell Programming and Scripting

Syntax error in script

I get this error when I try to run my script (BTW, this is a simple script I am supposed to write for my class) $ menuscript menuscript: syntax error at line 89 : `"' unmatched $ Here is the code (Any help is greatly appreciated) (Line numbers included) 1 #!/bin/ksh 2 ... (2 Replies)
Discussion started by: KindHead
2 Replies

9. Shell Programming and Scripting

Syntax error in a script...

Hi All, I have been fighting with a syntax error for the last 2 days, still haven't got the solution. Could you please help me, your help will be greatly appreciated. In my script I am getting a error in a for loop, its similar to the one as is below. for v_id in v1 v2 v3 v4 do... (8 Replies)
Discussion started by: rajus19
8 Replies

10. UNIX for Dummies Questions & Answers

Script syntax checking

Is it possible to check the script syntax with some sort of command...? Without running the script . I'm using Sun Solaris (3 Replies)
Discussion started by: bjornrud
3 Replies
Login or Register to Ask a Question