nixCraft Linux Forum

nixCraft

Linux / UNIX 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

Linux answers from nixCraft.


Shell scripting You can discuss the shell scripting, request shell scripts and scripting techniques

Reply

 

LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 23-10-2007, 06:44 PM
Junior Member
User
 
Join Date: Sep 2007
OS: CentOS
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
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
  #2 (permalink)  
Old 23-10-2007, 09:33 PM
Junior Member
User
 
Join Date: Sep 2007
OS: CentOS
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
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 23-10-2007, 10:43 PM
Junior Member
User
 
Join Date: Sep 2007
OS: CentOS
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
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 24-10-2007, 12:10 AM
monk's Avatar
Senior Member
User
 
Join Date: Jan 2005
Location: Tibet
OS: Debian GNU/Linux
Posts: 506
Thanks: 0
Thanked 8 Times in 6 Posts
Rep Power: 7
monk has a spectacular aura about monk has a spectacular aura about
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


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 Off


Similar Threads

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


All times are GMT +5.5. The time now is 11:24 AM.


Powered by vBulletin® Version 3.8.5 - Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2
©2005-2010 nixCraft. All rights reserved

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 37 38