nixCraft Linux Forum

nixCraft

Linux Tech Support Forum

Shell script to perform operation on remote server

This is a discussion on Shell script to perform operation on remote server within the Shell scripting forums, part of the Development/Scripting category; Hello I have a backup server. And I want to do this following operation 1. ssh to that backup server ...


Go Back   nixCraft Linux Forum > Development/Scripting > Shell scripting

Register FAQ Members List Calendar Forgotten your password? Mark Forums Read
  #1 (permalink)  
Old 10-23-2007, 07:44 PM
Junior Member
User
 
Join Date: Sep 2007
My distro: CentOS
Posts: 12
Rep Power: 0
vivekv is on a distinguished road
Default Shell script to perform operation on remote server

Hello

I have a backup server. And I want to do this following operation

1. ssh to that backup server (the remote server is already paired with my server,so no password entering screen)
2. fetch www.abc.com/file.zip
3. scp file.zip root@myserver.com:/home/user/www/file.zip


Its not joke, I know I can do this operation with wget. But its not what I want.

Because, The remote backup server only allows FTP and SSH access.
There is no http access( the server is rsyncpalace.com)


So, I have coded like this


<?php
$command="ssh user@backupserver.com"; // demo server
$output=shell_exec($command);

$command="fetch http://definitions.symantec.com/defs/20071022-017-v5i32.exe";
$output=shell_exec($command); // Sample file

$command="scp user@myserver.com:/home/user/www/20071022-017-v5i32.exe";
$output=shell_exec($command); // Sample file


print "<pre>$output</pre>\n"; //show output
?>


But It did not work.


Can anyone please let me know how to do this work?

I want php code. not pure shell code.

Not sure, how .cgi file will work , no idea

Please help me
Thanks
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 10-23-2007, 10:33 PM
Junior Member
User
 
Join Date: Sep 2007
My distro: CentOS
Posts: 12
Rep Power: 0
vivekv is on a distinguished road
Default

ok,almost all problems are solved now with the help of
nixCraft - Linux sys admin blog by Vivek
But I need 1 and only last help

I need to execute this command using PHP FILE


Code:
rsync -v -e ssh user@remoteserver.com:~/back/file.tar.gz /home/user/www/1
What this code will do is :

This will download a file called file.tar.gz from a remote server,remoteserver.com and will save it into /home/user/www/1


I checked this command via putty and is working.

But I need to add this command to a php file so that when a php file called download.php will execute, then this code must be executed.

How to do that ?

Any idea ?

Thanks
Reply With Quote
  #3 (permalink)  
Old 10-23-2007, 11:43 PM
Junior Member
User
 
Join Date: Sep 2007
My distro: CentOS
Posts: 12
Rep Power: 0
vivekv is on a distinguished road
Default

File : .cgi-bin/file.cgi


Code:
#!/bin/sh
echo Content-type: text/html
echo
echo
echo "<HTML>"
echo "<HEAD>"
echo "</HEAD>"
echo "<BODY>"
echo "<H2>Hard disk info:</H2>"
echo "<PRE>"
df-h
echo "</PRE>"
echo "</BODY>"
echo "</HTML>"

I want to replace "df -h" with this command

Code:
rsync -v -e ssh user@remoteserver.com:~/back/file.tar.gz /home/user/www/1
I changed , but its not working.

Reply With Quote
  #4 (permalink)  
Old 10-24-2007, 01:10 AM
monk's Avatar
Senior Member
User
 
Join Date: Jan 2005
Location: Tibet
My distro: Debian GNU/Linux
Posts: 482
Rep Power: 5
monk will become famous soon enough monk will become famous soon enough
Default

Well, you must run this command as web server user. You may be login as user foo using putty, but webserver run as nobody or apache or www-data user (depends upon Linux distro). So you need to configure ssh keys for your web server user too.

Code:
rsync -v -e ssh user@remoteserver.com:~/back/file.tar.gz /home/user/www/1
Another option is sudo
__________________
May the force with you!
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads

Thread Thread Starter Forum Replies Last Post
Tomcat shell script cron job to restart server kasimani Shell scripting 4 05-03-2008 08:46 PM
script hangs when a remote server is down vikas027 Shell scripting 2 11-11-2007 04:47 PM
Shell script to check the disk space on remote systems vijayscripts Shell scripting 5 10-21-2007 07:29 PM
Linux Shell script to mount remote windows share angelus_kit Shell scripting 2 09-06-2007 08:18 PM
Shell script to monitor remote local http or port 80 amigo28 Shell scripting 1 02-12-2007 10:58 PM


All times are GMT +5.5. The time now is 07:46 PM.


Powered by vBulletin® Version 3.7.4 - Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36