LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices


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

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


Hi,

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 :

Code:
PS=`/usr/bin/ncftpget -u UserName -p SomePassWord -V www.somesite.com . /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:
Code:
/usr/bin/ncftpget -u SomeUser -p WrongPass -V www.somesite.com . /store/auto_backup/*.sql.gz
ncftpget: cannot open www.somesite.com: 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
bgeddy
Senior Member
 
Registered: Sep 2006
Location: Liverpool - England
Distribution: slackware64 13.37 and -current, Dragonfly BSD
Posts: 1,810

Rep: Reputation: 232Reputation: 232Reputation: 232
Quote:
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 :

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

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


Reply

Tags
command, execute, ncftp, script, shell



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

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:38 PM.

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