HowTo: Execute A Script On Remote UNIX / Linux Server

by on May 27, 2009 · 4 comments· last updated at May 27, 2010

How do I execute a script on remote server called server2.example.com from my PC?

You can use ssh client (part of most UNIX / BSD / OS X and Linux distros) as follows to run any command or script on remote UNIX or Linux server as follows:

ssh user@server2.example.com script.name

You can execute the date command as follows on remote server:

ssh user@server2.example.com date

You may need to specify full script path. In this example, run /root/backup.sh script as follows:

ssh user@server2.example.com /root/backup.sh


You should follow me on twitter here or grab rss feed to keep track of new changes.

Featured Articles:

{ 4 comments… read them below or add one }

1 Yong Cao June 21, 2010 at 4:17 pm

This is very good and helpful stuff.
Thanks a lot
Yong Cao

Reply

2 jay P March 2, 2012 at 4:49 am

How can I add Password to this “ssh user@server2.example.com date”

Reply

3 webskein March 11, 2012 at 4:43 pm

jay – you could try “passwordless ssh”. There’s stuff on Google about that.

Reply

4 Murryy December 11, 2012 at 7:19 pm

will this work if the script on the remote is interative ? If not can anyone give more suggestions.
Thank you

Reply

Leave a Comment

You can use these HTML tags and attributes for your code and commands: <strong> <em> <ol> <li> <u> <ul> <kbd> <blockquote> <pre> <a href="" title="">

Tagged as: , , , , , , , , , ,

Previous Faq:

Next Faq: