LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices



Reply
 
Search this Thread
Old 05-23-2005, 04:29 AM   #1
MikeAtVillage
Member
 
Registered: May 2005
Location: Mid Wales (UK)
Distribution: Slackware 8.0, Suse 10.0/1/2, CentOS (SMEServer7)
Posts: 38

Rep: Reputation: 15
Looking for a remote "chown" command ?


Hi folks,

I written a small shell script which uses scp (and a public key) to put a file from my main server onto 6 other remote servers. Works OK but the file on the remote servers end up belonging to root. Is there a command I could use to chown the file on all 6 remote servers to another user in one action ? Or is there something other than scp which would retain original ownership settings ?

ATB

Mike - getting there, slowly but surely :-)

Here's my little script...

#!/bin/sh

## putfile.sh


## Script to put a file onto ALL Training Centre Servers from PTServer
##


TCSERVERS="172.16.172.21 172.16.86.7 172.16.15.7 172.16.132.44 172.16.63.7 172.16.158.7 172.16.50.7 172.16.145.5"

if [ $# -ne 2 ] ; then
echo "Error. Usage: putfile.sh source file, destination directory" >&2; exit 1
elif [ -z $2 ] ; then
echo "Error. No destination given" >&2; exit 1
fi

for server in $TCSERVERS ; do

scp $1 $server:$2/$(basename $1) > /dev/null
echo "Copying $(basename $1) to $server:$2/$(basename $1)"
done
 
Old 05-23-2005, 05:54 AM   #2
fr_laz
Member
 
Registered: Jan 2005
Location: Cork Ireland
Distribution: Debian
Posts: 384

Rep: Reputation: 32
You can use ssh to automatically execute a command and then logout :
Code:
ssh user@machine ls
 
Old 05-23-2005, 06:31 AM   #3
MikeAtVillage
Member
 
Registered: May 2005
Location: Mid Wales (UK)
Distribution: Slackware 8.0, Suse 10.0/1/2, CentOS (SMEServer7)
Posts: 38

Original Poster
Rep: Reputation: 15
Oh, silly me, why did I not try that !!!

Many thanks

Mike
 
Old 05-23-2005, 09:18 AM   #4
jschiwal
Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 655Reputation: 655Reputation: 655Reputation: 655Reputation: 655Reputation: 655
Check out the man page for scp. The -p option preserves permissions. You will need the user and group owner to be represented by the same UID/GID numbers.
 
Old 05-23-2005, 09:41 AM   #5
MikeAtVillage
Member
 
Registered: May 2005
Location: Mid Wales (UK)
Distribution: Slackware 8.0, Suse 10.0/1/2, CentOS (SMEServer7)
Posts: 38

Original Poster
Rep: Reputation: 15
Many thanks.

I already had the -p option in my script (I must have posted an older version in my original post ! sorry.) but the files all ended up on the remote servers as being owned by root/root. It is _very_ likely that the UID/GID on the remote server is not the same as those on the main server....

I've added a 3rd variable to my script to take the "new user" name and after scp transfers the file it is chown'd - or left as root if the variable is null.

Thanks

Mike - it's all gradually falling into place :-)
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Shell Script: Find "Word" Run "Command" granatica Linux - Software 5 07-25-2007 08:42 AM
"stalled" problem in " scp" command gentleshark Linux - Networking 1 08-29-2005 01:41 PM
Need Frontend to "chown" command TippyToes Linux - Software 3 11-24-2004 09:50 PM
Tiny Sofa 2.0 - I thought "halt", "reboot" were only root command ?? sorcerer Linux - Distributions 1 08-21-2004 04:28 PM
"segmentation error" when issuing "useradd" command through terminal with RH 9.0 kaihuang Linux - General 0 10-22-2003 12:47 AM


All times are GMT -5. The time now is 10:48 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration