chown remotely via ssh / invalid group


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting chown remotely via ssh / invalid group
# 1  
Old 09-01-2009
chown remotely via ssh / invalid group

Hi,

i have a problem with a shell script. I need to change the owner and group of a file on a remote machine.

I tried to use ssh but have some problems.

The code:
Code:
group=`ssh -t -t $1 -p 3344 "stat -c %G $cpath/FILE"`

echo " $2:$group "
echo $1
echo $cpath

ssh $1 -p 3344 "chown $2:$group $cpath/FILE

The Output if started with ./script.sh 192.168.0.99 scott
Code:
 scott:users
192.168.0.99
/backup/scott/data

chown: âscott:users\râ: ungültige Gruppe

Note: "ungültige Gruppe" = invalid group (there is a problem with special character " ü ")

Output if startet with sh -x script.sh 192.168.0.99 scott
Code:
++ ssh -t -t 192.168.0.99 -p 3344 'stat -c %G /backup/scott/data/FILE'
Connection to 192.168.0.99 closed.
+ group=$'users\r'

 'echo ' scott:users
 scott:users
+ echo 192.168.0.99
192.168.0.99
+ echo /backup/scott/data
/backup/scott/data

++ ssh 192.168.0.99 -p 3344 'chown scott /backup/scott/data/FILE'
 /backup/scott/data/FILE'wn scott:users
chown: âscott:users\râ: ungültige Gruppe

If i do " chown scott:users /backup/scott/data/FILE " there is no problem.

I think the problem is in the variable $group cuz it is containing this " \r " any hint where this comes from or how to get rid of it ?

Thank you
Greetings Linién

edit:
Additional Info:
OpenSSH_3.9p1, OpenSSL 0.9.7e 25 Oct 2004
Linux version 2.6.11.4-21.15-default (geeko@buildhost) (gcc version 3.3.5 20050117 (prerelease) (SUSE Linux)) #1 Tue Nov 28 13:39:58 UTC 2006

Last edited by Linien; 09-01-2009 at 09:47 AM..
# 2  
Old 09-01-2009
Hi,

Just a though that crossed my mind: are you using the same charset on both systems?
# 3  
Old 09-01-2009
Try writing the result of this part of your script to a file (from inside the script - not from command line):
Code:
group=`ssh -t -t $1 -p 3344 "stat -c %G $cpath/FILE"`

Open the file with vi, and turn on the display of invisible characters. This will show those funny windows characters (like ^M at the end of the line) - maybe there's a special character at the front.
Code:
:set list

Running this command does not change the file - you can easily toggle this feature off with:
Code:
:set nolist

# 4  
Old 09-02-2009
Thanks for your time.

Ok i changed the code to following:

Code:
ssh -t -t $1 -p 3344 "stat -c %G $cpath/FILE" > group.log

group=`cat group.log`

echo $group

ssh $1 -p 3344 "chown $2:$group $cpath/FILE"

When i open the group.log file with vi and :set list it looks like this:

Code:
users$
~
~
~
~
:set list                                     1,5           All

If i run the script with sh -x
Code:
+ ssh -t -t 192.168.0.99 -p 3344 'stat -c %G /backup/scott/data/FILE'
Connection to 85.214.147.44 closed.
++ cat group.log
+ group=$'users\r'
+ echo $'users\r'
users

 /backup/scott/data/FILE'wn scott:users
chown: âscott:users\râ: ungültige Gruppe

@ripat
Which charset i have to check ? Is there an extra charset for ssh ?

Since the server whos executing the script is an old SuSE 9.3 and the target machines are Debian (Etch) and RHEL and some other distributions... i guess its possible that the charset is not matching.

Greetings Linién
# 5  
Old 09-02-2009
Hmmm....

Your command is:
Code:
group=`ssh -t -t $1 -p 3344 "stat -c %G $cpath/FILE"`

Why are you using the -t -t option for ssh? Do you need the pseudo tty sessions?

Here's what I've tried. I created a script called sshtest.sh.
Code:
#!/bin/sh
group=`ssh $1 stat -c %G $2/FILE`
echo $group

I run it by passing two arguments - $1 and $2. $1 is the server to connect to and $2 is the path to the file.
Code:
./sshtest.sh myhost /var/tmp/testing

And the result is:
Code:
slocate

This is the group that owns the file.

See if you can accurately report on the current group for your files, then see if you can change the group ownership after that.
# 6  
Old 09-03-2009
MySQL

Quote:
Here's what I've tried. I created a script called sshtest.sh.
Code:
#!/bin/sh
group=`ssh $1 stat -c %G $2/FILE`
echo $group

I tried this with my server and it works.
Code:
sh -x sshtest.sh 192.168.0.99 /backup/scott/data
++ ssh 192.168.0.99 -p 3344 stat -c %G /backup/scott/data/FILE
+ group=users
+ echo users
users

I tried to implement this into my script but at first it wont work as expected.

But you were completely right. My problem was the pseudo tty (I used it just cause most of my other commands needed it for edit some files and execute some other shell scripts etc.)

So i changed my code from

Code:
group=`ssh -t -t $1 -p 3344 "stat -c %G $cpath/FILE"`

to

Code:
group=`ssh $1 -p 3344 stat -c %G $cpath/FILE`

And its working fine now.

Thanks for your help
Linién
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

[bash] running a function remotely using ssh

Hi all. I need a bash script to run a function remotely. I think it should be similar to the following but can't figure out the exact syntax. Here is the script: #!/bin/bash function nu () { for var in {0..5}; do printf "$var, "; done; echo } ssh host "$(typeset -f); nu" ... (9 Replies)
Discussion started by: ziguy
9 Replies

2. Solaris

How to remotely start ssh on Solaris?

Hi everyone, I have a Solaris machine: SunOS 5.10 Generic_127127-11 sun4v sparc SUNW,SPARC-Enterprise-T5220 After reboot, I can't ssh to this machine. Error message: ssh: connect to host xxxx port 22: Connection refused It seems ssh daemon is not running, but I don't have... (5 Replies)
Discussion started by: Zaiwen Gong
5 Replies

3. Solaris

SSH Remotely

Hello. I am trying to ssh and run a script from a remote computer. These computers will be both Windows and MACs. I am using Solaris 8 and what I have tried is: using putty ssh user@ip_address (remote command) /folder/folder/filename.sh The issue here is that the user profile has not... (3 Replies)
Discussion started by: jkmtm
3 Replies

4. UNIX for Dummies Questions & Answers

Chown... cannot get the login group of a numeric UID

How do I resolve the below error. I want to change the ownership on sf_Temp file from media to dba. # grep ^media /etc/group # ls -l drwxrwx--- 1 root vboxsf 0 Feb 1 16:10 sf_Temp drwxrwx--- 2 root vboxsf 4096 Jan 31 17:59 sf_VBoxShared dr-xr-xr-x 6 oracle root 2048 Dec 19 09:20... (4 Replies)
Discussion started by: lutus
4 Replies

5. Shell Programming and Scripting

ssh execute command remotely

Hi all, Today I want to write a script to run the commands remotely. If I run the command as follows: ssh <user>@<ip> 'ls; pwd' it works fine. But when I want to use ssh to set view in clearcase, it will lose the response. as follows ssh <user>@<ip> 'cleartool setview <view_name>; pwd'... (1 Reply)
Discussion started by: Damon_Qu
1 Replies

6. Solaris

Delay after invalid SSH logon?

I am trying to configure a 4 second delay between failed login attempts on SSH. (1 Reply)
Discussion started by: LittleLebowski
1 Replies

7. Shell Programming and Scripting

remotely append crontab over ssh

Hi I would like to append/modify crontab remotely over ssh and this is what i have tried so far. text.txt contains the following line. 0,15,30,45 * * * * /home/local/hello.sh cat text.txt |ssh $host 'tee' but i dont know how to edit the crontab here after piping it to tee command. (2 Replies)
Discussion started by: xiamin
2 Replies

8. UNIX for Advanced & Expert Users

connecting windows remotely from unix using SSH

Hi Can someone giv me some knowledge on accesing windows from unix and executing DOS scripts using SSH I would like to know how to go abt it...am new to it. Thanks in advance (1 Reply)
Discussion started by: lakshmis10
1 Replies

9. UNIX for Advanced & Expert Users

using ssh change password remotely?

Is it possible to change the password using a shell script, I want to remotely connect to a computer and then change password without manual intevention. Thanks in Advance Rishi (4 Replies)
Discussion started by: RishiPahuja
4 Replies

10. Shell Programming and Scripting

Not able to remotely connect to server using ssh

Hi, I am trying to run the below command in perl but when the perl script is executed it prompts a error message saying " ssh: <username>: Name or service not known ". Not able to understand this as this command runs perfectly on the server prompt. ` ssh <username>@pus4026dev df -k >>... (2 Replies)
Discussion started by: be2sp1
2 Replies
Login or Register to Ask a Question