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
exec Remote server? imager Shell Programming and Scripting 1 07-23-2009 01:38 PM
ssh and remote command exec `uname -r` jbmukund Shell Programming and Scripting 5 05-07-2008 07:15 PM
Remote Exec TheEngineer AIX 1 05-12-2006 04:50 AM
remote execution pascalbout AIX 2 01-03-2006 06:20 AM
exec 3 execution snehal UNIX for Advanced & Expert Users 0 11-16-2005 08:11 AM

Reply
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 3 Weeks Ago
royalbull royalbull is offline
Registered User
  
 

Join Date: Nov 2009
Posts: 4
remote execution of find -exec

Hi folks

I am working on a script which lists files of a specific pattern on a remote m/c and tar&zip them to another remote m/c via a centralized server.

M/C details:

remote1 - OSF1 vayu V5.1 2650 alpha
remote2 - cygwin based windows server
central - SunOS phys-chenab 5.8 Generic_117350-61 sun4u sparc SUNW,Sun-Fire-15000

LAYOUT
*******

remote1(vayu) -------> central (chenab) ----------> remote2 (cygwin windows)


Have a issue with the script which seriously retards me . The logic is to check if a particular file has already been transferred , and if not transfer the same . This checking happens at the remote side through remsh. This part works well when executed directly on remote1 but fails when executed from central server.


set -f;cd /usr1/smscomn/data/cards/spool/ ;find /usr1/smscomn/data/cards/spool/ -name "CS507.11.[0-9]*.47.*" -exec bash -c ' grep $0 /usr1/smscomn/data/cards/status_vayu | grep success ; if [ `echo $?` -eq 0 ] ;then printf "$0 copied \n" ; else printf " $0 transferred already \n" ; fi ' {} {} \; ;set +f


remsh vayu "set -f;cd /usr1/smscomn/data/cards/spool/ ; find /usr1/smscomn/data/cards/spool/ -name "CS507.11.[0-9]*.47.*" -exec bash -c ' grep $0 /usr1/smscomn/data/cards/status_vayu | grep success ; if [ `echo $?` -eq 0 ] ;then printf " copied"; echo $0 ; else printf $0 transferred ; fi ' {} {} \; ;set +f "


Output:

copiedbash
copiedbash
copiedbash
copiedbash



$0 parameter of bash -c should be filename output of find but why is it pointing to prog name which is bash .

Moreover when i change bash -c to sh -c , i expect output to be "copiedsh" ; but its still "copiedbash"

Can you please provide some light on whats happening? . I am open to corrections and suggestions and even harsh rebuke over insanity of the code.
  #2 (permalink)  
Old 3 Weeks Ago
methyl methyl is offline
Registered User
  
 

Join Date: Mar 2008
Posts: 1,175
The one-line-remsh approach is much too complicated. There are too many issues to deal with even though it might be possible make it work eventually.
e.g.
Which computer expands "*".
When we match double quote characters, what characters are between the pairs of double quotes? What characters are not between double quotes?
Which computer breaks the command line on seeing a semi-colon?

You will be best advised to create the script on the remote server as a properly laid out readable script, and then execute the script with:

Code:
remsh servername -l username -n "/pathtoscript/scriptname"
Note: You may not require the "-n" switch in this context.
  #3 (permalink)  
Old 3 Weeks Ago
royalbull royalbull is offline
Registered User
  
 

Join Date: Nov 2009
Posts: 4
Your suggesstion is quite acceptable and i have implemented it. Thanks for your suggestion . Still the vagueness of the code haunts me and keeps me trying to debug it repeatedly.

Figuring out what exactly is happening is more than enough for me as it shall explain me shell's construct .

Any other suggestions ????
Reply

Bookmarks

Tags
bash -c, find, find -exec, remsh

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:44 AM.


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