Welcome to WebmasterWorld Guest from 54.224.13.210

Forum Moderators: bakedjake

Message Too Old, No Replies

Help with bash script

syntax seems correct

     
2:58 pm on Jan 5, 2007 (gmt 0)

Junior Member

10+ Year Member

joined:Oct 10, 2006
posts:41
votes: 0


Using SuSe 10.1, I have a shell script that checks a PSV file and if the file has content (greater than zero) loads an sql text command into MySQL. The syntax seems correct, but I get an error that a there is an unrecognized "token" before "fi".

The file is named pipefilechk.sh and it is in the /bin/ folder. I try to call it in command line with "exec pipefilechk.sh".

I also have it in a crontab, but it is not working.

*******************
#!/bin/bash

if [-s /usr/local/src/blist.psv];
then

/usr/bin/mysql -u someuser -p somepassword < /usr/local/src/blist.sql;
fi
********************

When I just type the "then" command directly into command line, it works.

3:41 pm on Jan 5, 2007 (gmt 0)

Preferred Member

10+ Year Member

joined:Sept 28, 2002
posts:505
votes: 0


2 things to try:
- remove both trailing ';'
- the ' [ ' and ' ] ' should each have a space before and after so it should read
if [ -s /usr/local/src/blist.psv ]

The ' [ ' is not just a bracket, it is the test command.

Kind regards,
R.

6:23 pm on Jan 5, 2007 (gmt 0)

Junior Member

10+ Year Member

joined:Oct 10, 2006
posts:41
votes: 0


Thanks. I had tried removing the ; and I noticed the [ spaces ] after posting here.

The more I read, though, the more I realize that this whole issue is specific to bash syntax and shell commands. It is a mess, because my script is using reserved shell commands (-u and -p in the mysql command, and the dot in the files).

This is why it was seing "tokens".

I can't find a work around in the manual or reference files. And only someone who knows shell can answer this.

I suspect it can only be done with assigning variables. But the actual syntax is still escaping me (no pun).

 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members