Welcome to the most active Linux Forum on the web.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 01-25-2009, 04:42 PM   #1
LQ Newbie
Registered: Nov 2006
Distribution: Ubuntu
Posts: 3

Rep: Reputation: 0
[shell script] execute command and parse output


I have been trawling the WWW for some time now, trying to find an answer to my problem.

I'm writing a shell script (bourne) intended for backing up a database on a remote phpbb bulletin site (ftp access only) and moving the backup to a local machine.

Right now I can generate a DB dump on the remote site and ftp it to my local machine using ncftpget.

The problem is when I try to parse the output from ncftpget in order to determine how the transfer went.

The command is executed like this from within the script :

PS=`/usr/bin/ncftpget -u UserName -p SomePassWord -V . /store/auto_backup/*.sql.gz`
echo "Echo : $PS"
In the case of an error (wrong pass) the command will output this if run directly from the shell:
/usr/bin/ncftpget -u SomeUser -p WrongPass -V . /store/auto_backup/*.sql.gz
ncftpget: cannot open username and/or password was not accepted for login.
The error is never stored in the $PS variable and thus cannot be evaluated.
I have written other scripts that did not have this problem...

I know this may seem like a trivial problem to some, but I have been scratching my head quite a bit trying to figure this one out.

Any comments/feedback appreciated!
Old 01-25-2009, 04:53 PM   #2
Senior Member
Registered: Sep 2006
Location: Liverpool - England
Distribution: slackware64 13.37 and -current, Dragonfly BSD
Posts: 1,810

Rep: Reputation: 231Reputation: 231Reputation: 231
The error is never stored in the $PS variable and thus cannot be evaluated.
Possibly the error is being written to sdterr rather than stdout. Try this to test :

PS=$(/usr/bin/ncftpget -u UserName -p SomePassWord -V . /store/auto_backup/*.sql.gz 2>&1)
echo "Echo : $PS"
This simply redirects stderr to stdout.
Old 01-26-2009, 01:49 AM   #3
LQ Newbie
Registered: Nov 2006
Distribution: Ubuntu
Posts: 3

Original Poster
Rep: Reputation: 0
That did the trick! Thank you


command, execute, ncftp, script, shell

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
how to execute Source command in a shell script UltraSoul Linux - General 3 09-23-2010 10:13 AM
Not able to execute Oracle Sql command in shell script Ranvijaidba Programming 3 10-23-2008 03:45 PM
Help!! Shell script to get output of ls -l command into an array kasthana Programming 8 06-01-2008 11:37 PM
Shell script to parse csv-like output, row by row utahnix Linux - General 8 12-08-2007 05:03 AM
How to execute a command line in a shell script orgazmo Programming 5 05-09-2005 09:16 AM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:06 PM.

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