LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
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 03-14-2009, 09:54 AM   #1
debicool
LQ Newbie
 
Registered: Mar 2009
Posts: 1

Rep: Reputation: 0
How to find out what is causing command not found in script


I have a very small script which queries a mySQL table and puts the result into a variable. Actually that is what I want to do.

When I just run the mysql command on the command line it works fine.
Put into the script and run the script the script returns the result plus has at the end the command not found as well.
see below... 23 is the actual result from the query but what is causing the command not found at the end?

./myscript.sh: line 4: 23: command not found

How can I figure out what is causing that.

Below my code
#!/bin/sh
#

sqlcount= `mysql --host=host --user=user --password=apassword --silent --skip_column_names -e"SELECT count(*) as Users_Logged_On FROM user_logon u WHERE logon_state='Logged On' and LOGON_DT >= curdate();" aDatabase`

echo $sqlcount
 
Old 03-14-2009, 09:56 AM   #2
pwc101
Senior Member
 
Registered: Oct 2005
Location: UK
Distribution: Slackware
Posts: 1,847

Rep: Reputation: 128Reputation: 128
Assigning a value to a variable is as follows:
Code:
val=1
valnext=something
Remove the space between the = and your backticked command:
Code:
#!/bin/sh
#

sqlcount=`mysql --host=host --user=user --password=apassword --silent --skip_column_names -e"SELECT count(*) as Users_Logged_On FROM user_logon u WHERE logon_state='Logged On' and LOGON_DT >= curdate();" aDatabase`

echo $sqlcount
Your error was that the output of your mysql command was 23, which sh was trying to execute as a command, which it couldn't.

Last edited by pwc101; 03-14-2009 at 09:58 AM.
 
  


Reply



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
BASH Script - command not found!! JavaNinja Linux - Newbie 12 12-01-2008 11:45 AM
egrep to find a command not found string romainp Linux - General 1 09-07-2007 03:30 PM
Bash script says command not found - why? RavenLX Ubuntu 3 08-03-2007 02:19 PM
Bash Script; command not found twintornado Programming 2 06-01-2005 09:59 AM
command not found (My shell script) Swift&Smart Linux - Software 3 05-15-2004 11:14 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 08:06 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
Open Source Consulting | Domain Registration