remote execution of find -exec

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting remote execution of find -exec
# 1  
Old 11-05-2009
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


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 "



$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  
Old 11-05-2009
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.
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:

remsh servername -l username -n "/pathtoscript/scriptname"

Note: You may not require the "-n" switch in this context.
# 3  
Old 11-05-2009
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 ????
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Pause processes in remote host and resume execution in another remote host

Hi, Given addresses of 2 remote machines, using a shell script is it possible to get the state of running processes in "src" stop all the processes in "src" exit out of "src" ssh into "dest" resume the state of executing processes captured in step 1 in "dest" Assumption: "src" is... (3 Replies)
Discussion started by: Saeya Darsan
3 Replies

2. Shell Programming and Scripting

find: missing argument to `-exec' while redirecting using find in perl

Hi Friends, Please help me to sort out this problem, I am running this in centos o/s and whenever I run this script I am getting "find: missing argument to `-exec' " but when I run the same code in the command line I didn't find any problem. I am using perl script to run this ... (2 Replies)
Discussion started by: ramkumarselvam
2 Replies

3. UNIX for Dummies Questions & Answers

Remote file execution

Hello, I'm new to scripting so, sorry if this is a dumb question. What's the best way to execute a .sh file remotely? I want to log into server "b" from server "a" & run a script. "./". At this point, all I'm looking to do is a simple ls -la > output.txt within the script to capture... (3 Replies)
Discussion started by: crunch10c
3 Replies

4. Shell Programming and Scripting

exec Remote server?

I use this code to remove old backupfiles on the local system. exec('/usr/bin/sudo find /backup/daily-con* -mtime +7 -exec rm {} \;') I would also like to run this command on a remote system that is on the same network. ( My question is can this be done and if so how. ... (1 Reply)
Discussion started by: imager
1 Replies

5. Shell Programming and Scripting

Remote command execution

We have multiple Unix servers and a particular command can only be executed in one of the box from a specific path. I have password-less ssh set up for all the boxes. I am unsure the command to use to execute that particular command from any other box. To be specific say program named _my_exe_ can... (4 Replies)
Discussion started by: uunniixx
4 Replies

6. Shell Programming and Scripting

ssh and remote command exec `uname -r`

Hi guys, I am trying to do a ssh for performing a set of actions. Find it below: I need to put the user/ kernel/ DISTRO variables before I complete this operation. what I observed is when ever I put a `command` in those quotes, it performs thta action in local system rather than remote one.... (5 Replies)
Discussion started by: jbmukund
5 Replies

7. AIX

Remote Exec

Dears we have an application that try to excute commands via using a (rexec.dll) to connect to an AIX box and running commnds but when we try to do that then the connection will be rejected by the AIX box, are there any pre-configurations or settings that must be done in order to gain the... (1 Reply)
Discussion started by: TheEngineer
1 Replies

8. AIX

remote execution

good morning I would like copy and execute a shell script on a remote server telnet is not autorize, so i use ssh: scp to copy and ssh to execute But with the scp, the permissions are not saved and the file 's permission on the remote server is r--r--r-- , so i can't execute it Can you help... (2 Replies)
Discussion started by: pascalbout
2 Replies

9. UNIX for Advanced & Expert Users

exec 3 execution

Dear All, while opening new subscript file using "exec 3> $3" say for e.g. for some condition output is to be redirected to third argument passed. I am getting error exec not found . I think new subscript redirection file not getting opened. Plz help me out. Snehal \\ (0 Replies)
Discussion started by: snehal
0 Replies

10. Shell Programming and Scripting

remote execution

Hi everybody, sorry if the question will be too trivial for some of you, but I'm not a unix shell programmer expert. I need to write a script that allows me to rlogin to another machine, check the load (cpu and mem usage) of the new machine, start a process (that will run in the background) and... (5 Replies)
Discussion started by: ragmelo
5 Replies
Login or Register to Ask a Question