• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 216
  • Last Modified:

Running commands from a remote server

Hi,

I am making a shell script thats going to be a cron job that uploads various data to another server (using scp).

However, i like to also erase those files that are 1 week old.  however, i can think of a way of running a command from my script so it does it on the remote server.

i am sure its simpler than i think.  any suggestions?


this is the command i like to run.
find ~/.backup ­mtime +7 -exec rm -v {} / ;

also i only want to erase those files in the .backup folder.  i dont want it go into any sub-dirs or other trees.  just look in .backup and thats it.

did i construct my find correctly as well?  thanks.
0
jwnrb
Asked:
jwnrb
  • 3
  • 2
1 Solution
 
jwnrbAuthor Commented:
as whats wrong with this?

rsh foobar -l me find ~/hh532.backup -mtime +7 -exec rm -v {} \;

0
 
yuzhCommented:
rsh doesn't understand ~/hh532.backup , not sure you version of OS undersstand "rm -v filename". if you only want to delete regular file only, use "-type f" with find as well.

use can use full-path for find to search:
rsh foobar -l me "find ~/hh532.backup -mtime +7 -exec rm {} \;"

OR:
rsh foobar -l me "cd /path-to/hh532.backup ; find . -mtime +7 -exec rm {} \;"

BTW, rsh is not secure, consider to use secure shell (ssh) instead.



0
 
jwnrbAuthor Commented:
i think somehting like this should work then
ssh me@foobar 'find ~/.backup -mtime +7 -exec rm -v {} \;'

i jsut tested it and it seemed to be fine.

i am using debian linux kernel 2.4.18
0
 
yuzhCommented:
Yes, the you ssh command line systax is correct.

or you can do:

ssh -l me foobar "find ~/.backup -mtime +7 -exec rm -v {} \;"

Cheers!

0
 
jwnrbAuthor Commented:
well it was my quotes that was causing the problem look at that!  and you helped my realise rsh is not good and to use ssh (which was my gut instinct, just wasnt sure :-/ )

i was getting errors with -exec so i though the entire find was wrong

0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now