?
Solved

Running commands from a remote server

Posted on 2003-03-30
5
Medium Priority
?
212 Views
Last Modified: 2013-12-16
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
Comment
Question by:jwnrb
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 

Author Comment

by:jwnrb
ID: 8235676
as whats wrong with this?

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

0
 
LVL 38

Accepted Solution

by:
yuzh earned 300 total points
ID: 8235869
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
 

Author Comment

by:jwnrb
ID: 8236095
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
 
LVL 38

Expert Comment

by:yuzh
ID: 8236177
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
 

Author Comment

by:jwnrb
ID: 8236467
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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Network Interface Card (NIC) bonding, also known as link aggregation, NIC teaming and trunking, is an important concept to understand and implement in any environment where high availability is of concern. Using this feature, a server administrator …
Google Drive is extremely cheap offsite storage, and it's even possible to get extra storage for free for two years.  You can use the free account 15GB, and if you have an Android device..when you install Google Drive for the first time it will give…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Suggested Courses
Course of the Month8 days, 12 hours left to enroll

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question