ssh to remote server and delete files older than 7 days

After establishing a trust relationship between the local and remote server (public-private key pair), you can ssh into the remote server without being prompted for credentials. The below script can be useful to login to remote server and delete old files:

ssh -t -t servername.domainname.com <<EOM
find /var/dbbackup/jira -mtime +7 -exec rm {} \;
exit
EOM

To replace days by minutes (multiply by 60 if you have hours), replace “-mtime +Xdays” with “-mmin +Xmins”

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s