LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
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 11-12-2012, 07:15 AM   #1
manju98458
LQ Newbie
 
Registered: Nov 2012
Posts: 18

Rep: Reputation: Disabled
Unhappy FTP Script


Greetings,

I am trying to create SFTP script to test the SFTP connectivity



issue is that I cannt able to satisfy both if and elif condition

Suggest me where iam missing in the script.

Last edited by manju98458; 11-12-2012 at 08:46 PM.
 
Old 11-12-2012, 10:06 AM   #2
michaelk
Moderator
 
Registered: Aug 2002
Posts: 11,810

Rep: Reputation: 721Reputation: 721Reputation: 721Reputation: 721Reputation: 721Reputation: 721Reputation: 721
Welcome to LinuxQuestions.

Just some observations. Is your server configured for public/private keys? The -b option is for non interactive commands so it does not appear to be used correctly. What is the contents of /SFTP/currentstatus.dat? And sftpSTATUS is never updated with the latest status.

To prove sftp functionality are you trying to send or receive a file from the server?
 
Old 11-12-2012, 10:24 AM   #3
manju98458
LQ Newbie
 
Registered: Nov 2012
Posts: 18

Original Poster
Rep: Reputation: Disabled
SFTP is configured for Public key we are accessing the external SFTP server from our linx boxes.

yes that's true Sftp STATUS never updated.

We just connect to SFTP and we are not receiving any file from the server

Last edited by manju98458; 11-14-2012 at 08:51 AM.
 
Old 11-12-2012, 10:26 AM   #4
unSpawn
Moderator
 
Registered: May 2001
Posts: 26,998
Blog Entries: 54

Rep: Reputation: 2745Reputation: 2745Reputation: 2745Reputation: 2745Reputation: 2745Reputation: 2745Reputation: 2745Reputation: 2745Reputation: 2745Reputation: 2745Reputation: 2745
Quote:
Originally Posted by manju98458 View Post
Suggest me where iam missing in the script.
- Using string comparison where exit value should do:
Code:
echo quit > /tmp/sftpcmds.$$
sftp -o ConnectTimeout=3s -q -b /tmp/sftpcmds.$$ user@host >/dev/null 2>&1
case $? in 
 0) echo OK;; 
 *) echo "Returned: $?;; 
esac
- Using odd paths like "/SFTP/" (see the FHS), dumping files in the CWD and not using mktemp ('man mktemp' for more),
- Using fixed values instead of getopts ('help getopts') and user input ('help read'),
- Probably should be using FUSE SSHFS or AutoSSH,
- Not business-like text but using unnecessary text amelioration like "###" and "---" lines,
- Duplicate echo commands,
- No timeouts / retesting: your "Dear Team," is not going to like you sending emails often.
*Search LQ for "Bash scripting guides".
 
Old 11-12-2012, 10:35 AM   #5
manju98458
LQ Newbie
 
Registered: Nov 2012
Posts: 18

Original Poster
Rep: Reputation: Disabled
Also I am thinking to use export , is it possible to store the sftpstatus output within the script to avoid the /tmp usage
 
Old 11-12-2012, 09:39 PM   #6
manju98458
LQ Newbie
 
Registered: Nov 2012
Posts: 18

Original Poster
Rep: Reputation: Disabled
Script for SFTP Status checking

Looking for a Script to check SFTP status with EXPORT to satisfy both

the below conditions

Last edited by manju98458; 11-14-2012 at 08:51 AM.
 
Old 11-12-2012, 10:37 PM   #7
schneidz
Senior Member
 
Registered: May 2005
Location: boston, usa
Distribution: fc-15/ fc-19-live-usb/ aix
Posts: 3,842

Rep: Reputation: 590Reputation: 590Reputation: 590Reputation: 590Reputation: 590Reputation: 590
not sure i understand ?:
Quote:
Originally Posted by manju98458 View Post
Looking for a Script to check SFTP status with EXPORT to satisfy both

the below conditions

Code:
if [[ "$sftpSTATUS" = "success" ] && [ "$currentSTATUS" = "failed" ]]
then
 do something
elif [[ "$sftpSTATUS" = "failed" ] && [ "$currentSTATUS" = "success" ]]
then
 do something else
fi
Please let me know if any scripts
 
Old 11-12-2012, 11:59 PM   #8
manju98458
LQ Newbie
 
Registered: Nov 2012
Posts: 18

Original Poster
Rep: Reputation: Disabled
We have to monitor the SFTP server connectivity. Everday we have to monitor whether the connectiy was succesfull or not. if it's successul or failed it has send alert message for failed condition and also for the restoration of the services

Last edited by manju98458; 11-13-2012 at 12:02 AM.
 
Old 11-13-2012, 07:59 AM   #9
schneidz
Senior Member
 
Registered: May 2005
Location: boston, usa
Distribution: fc-15/ fc-19-live-usb/ aix
Posts: 3,842

Rep: Reputation: 590Reputation: 590Reputation: 590Reputation: 590Reputation: 590Reputation: 590
the variable $? contains the exit status of the previous command.
Code:
scp user@server.net
if [ $? -eq 0 ]
then
 mail -s "success" user@server.net
else
 mail -s "failure" user@server.net
fi
 
Old 11-14-2012, 08:50 AM   #10
manju98458
LQ Newbie
 
Registered: Nov 2012
Posts: 18

Original Poster
Rep: Reputation: Disabled
I have written script some how I was not succesfull. Please look into it and correct me if my coding is wrong to execute

Last edited by manju98458; 11-14-2012 at 09:39 AM.
 
Old 11-14-2012, 08:57 AM   #11
unSpawn
Moderator
 
Registered: May 2001
Posts: 26,998
Blog Entries: 54

Rep: Reputation: 2745Reputation: 2745Reputation: 2745Reputation: 2745Reputation: 2745Reputation: 2745Reputation: 2745Reputation: 2745Reputation: 2745Reputation: 2745Reputation: 2745
Change
Code:
#!/bin/bash
to read
Code:
#!/bin/bash -vxe
then run script again and pipe stdin + stderr to a file through 'tee':
Code:
/path/to/script 2>&1 | tee /path/to/log.txt
then read "/path/to/log.txt" for clues. If you don't get it post the output using [code]vBB code tags[/code].
 
1 members found this post helpful.
Old 11-14-2012, 09:07 AM   #12
schneidz
Senior Member
 
Registered: May 2005
Location: boston, usa
Distribution: fc-15/ fc-19-live-usb/ aix
Posts: 3,842

Rep: Reputation: 590Reputation: 590Reputation: 590Reputation: 590Reputation: 590Reputation: 590
i have a general suggestion that isnt specific to your error but wouldnt it much simpler to use scp since this is automated ?

even mounting thru sshfs would be easier.
 
Old 11-14-2012, 09:12 AM   #13
schneidz
Senior Member
 
Registered: May 2005
Location: boston, usa
Distribution: fc-15/ fc-19-live-usb/ aix
Posts: 3,842

Rep: Reputation: 590Reputation: 590Reputation: 590Reputation: 590Reputation: 590Reputation: 590
Quote:
Originally Posted by unSpawn View Post
Change
Code:
#!/bin/bash
to read
Code:
#!/bin/bash -vxe
then run script again and pipe stdin + stderr to a file through 'tee':
Code:
/path/to/script 2>&1 | tee /path/to/log.txt
then read "/path/to/log.txt" for clues. If you don't get it post the output using [code]vBB code tags[/code].
to add to the good advice above, i think that echo is the best debugging tool.

i usually add lines like echo enter if / echo var = $var...
and then comment them out later.
 
  


Reply


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
Bash script problem with ftp session exiting the script early edomingox Programming 5 02-23-2010 05:39 AM
FTP script quest4net Linux - Newbie 4 04-08-2008 01:34 PM
ftp with a script shipon_97 Linux - Newbie 6 01-02-2008 05:16 AM
Urgent Help: Perl FTP Script Using NET::FTP xboxter Programming 8 05-16-2005 06:57 PM
ftp script dlm4444 Linux - Networking 5 02-10-2004 11:41 PM


All times are GMT -5. The time now is 03:58 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration