The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Backup script dan86 Shell Programming and Scripting 1 10-29-2007 08:47 PM
Backup Script tayyabq8 UNIX for Dummies Questions & Answers 0 01-21-2006 05:09 AM
A backup script pascal Shell Programming and Scripting 2 09-09-2005 08:53 AM
Backup Script geek4sur AIX 7 05-24-2005 10:31 AM
Help with a backup script SemperFi UNIX for Dummies Questions & Answers 5 07-22-2004 11:00 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 11-23-2008
rajwinder rajwinder is offline
Registered User
  
 

Join Date: Jun 2008
Posts: 26
Backup Script

I wrote a simple backup script but want to do some error handling ..

So this script do all the stuff and finally creates one tar file on remote machine using :

Code:
/usr/local/bin/tar cvzf - -T $ListFileName | /usr/local/bin/ssh trusteduser@192.168.32.2 "cat > /appl/test/$BTYPE-$APP-`date +%Y%m%d`.tar.gz"
trusted user can login without password due to ssh trust .. It works fine but here is the issue .. What if something happened to ssh trust the bash script will prompt for password and that is it .

Now i thought of couple of things :

1. Check for ssh trust before executing tar by :

/usr/local/bin/ssh trusteduser@192.168.32.2 'exit'

but again it will not work if it ask for password

2. execute the above command in a kind of subshell and wait for output till 5- 10 seconds and then exit .. not sure how to do this. Wait command will not kill it if didnt fininshed before n secods.

Please suggest
  #2 (permalink)  
Old 02-03-2009
otheus's Avatar
otheus otheus is offline Forum Staff  
Moderator ala Mode
  
 

Join Date: Feb 2007
Location: Innsbruck, Austria
Posts: 1,886
The last week of November can be a little tricky to get any American to answer questions. We're all sleeping after eating whole Turkeys.

Try this:
Code:
ssh -o Numberofpasswordprompts=0 trusteduser@192.168.32.2 true
If SSH needs to prompt for a password, it will see that it can prompt 0 times, and try another authentication method. If none can be found, it will exit with 255 and the message:
Code:
Permission denied (publickey,gssapi-with-mic,password).
The "true" runs the command "true" on the remote host, guaranteeing a zero result. So you can just do this:
Code:
if ssh -o Numberofpasswordprompts=0 trusteduser@192.168.32.2 true; then
   true;
else
   echo >&2 Cannot reach remote server without login prompt.
   exit 1
fi

<your tar|ssh command>
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 12:02 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0