1844172 Members
2495 Online
110229 Solutions
New Discussion

About shell script

 
juno2
Super Advisor

About shell script

I am not very clear about the ux shell script , please suggest how to make such a script , the function is to let the user to gzip and file and then rcp the gzipped file to other path .

for example there is a script called "ux_script" , the user input the file "file1" , then gzip the file1 (the gzipped file should be called file1.gz) , then rcp the file from the path /tmp to /usr .

$pwd
/tmp
$ux_script file1
$cd /usr
$ls -1
file1.gz

On the other hand, the /usr is on the remote system , because the difference of user permission , how can I login the remote system as other user before rcp the file ? thx in advance.
10 REPLIES 10
Graham Cameron_1
Honored Contributor

Re: About shell script

There are a couple of issues.

1. The shell script. Here's an example:

--
#!/usr/bin/sh
if [ ! -n "$1" ]
then
echo "Usage: $0 filename"
exit
fi
if [ ! -s $1 ]
then
echo "Cannot read $1"
exit
fi
gzip -c $1 > ${1}.gz && rcp ${1}.gz remotesys:/usr
--

2. The rcp permissions.
For that above rcp to work you need a .rhosts or hosts.equiv entry on the target machine.
eg if your source machine is called "box1" and your userid is "juno2", then on the target system, create a file in your home directory called .rhosts, containing the following line:
box1 juno2
You can test this works by running "remsh remotesys ls" - it should list files on the remote box (box2)

Good luck

-- Graham
Computers make it easier to do a lot of things, but most of the things they make it easier to do don't need to be done.
juno2
Super Advisor

Re: About shell script

thx reply , for the problem 2 , the user id in two ux machines is different , it can't use rlogin , how can I do the login as other user ? thx.
Graham Cameron_1
Honored Contributor

Re: About shell script

1. In the sctipt, change "rcp" to
"rcp -l touser"

2. On the target box, put the .rhosts entry in the home directory of touser.

-- Graham
Computers make it easier to do a lot of things, but most of the things they make it easier to do don't need to be done.
juno2
Super Advisor

Re: About shell script

thx reply , how about the password of touser , how to input the password ? thx
Graham Cameron_1
Honored Contributor

Re: About shell script

You don't need the password of touser if you set up the .rhosts file as explained.

But if you *want* to enter the password, then change
rcp ${1}.gz remotesys:/usr
to
cat ${1}.gz|rexec remotesys -l touser "cat > /usr/${1}.gz"

-- Graham
Computers make it easier to do a lot of things, but most of the things they make it easier to do don't need to be done.
juno2
Super Advisor

Re: About shell script

thx reply, but i found the rcp is not support the " -l" , how can I change the user ? thx
Graham Cameron_1
Honored Contributor

Re: About shell script

My apologies. You are right.
If you are using rexec, the -l is required.

If you are using rcp, the syntax is
different, as follows:

rcp ${1}.gz touser@remotesys:/usr

You will need so set up .rhosts under homedir of touser on remotesys as said earlier.
Hope that does it

-- Graham
Computers make it easier to do a lot of things, but most of the things they make it easier to do don't need to be done.
Hoefnix
Honored Contributor

Re: About shell script

rcp uses username like next host:file-string:
user_name@hostname:pathname/filename

So:
rcp local-file user_name@hostname:/path/remote_filename
juno2
Super Advisor

Re: About shell script

thx all reply, it is ok now, but still hv a problem , I am not want to gzip the f ile before rcp the file , what I want is to compile a program and then rcp to remote host , the original file name is file1.cdr , the compiled file name is file1.cbt , could suggest a new script , how can the system can rcp the file "file1.cdt" ? thx in advance
juno2
Super Advisor

Re: About shell script

May be my question is not very clear , I stated it again, I have a script which can compile a file ( eg. file1.cdr ) , the compiled file is .cbt extension ( eg. file1.cbt ) , how can I rcp the compiled file file1.cbt (instead of file1.cdr.cbt ) to the remote site ? thx.

$pwd
/tmp
$my_script file1.cdr
$pwd
/usr
$file1.cbt