LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Stuck on sript to scp a file (https://www.linuxquestions.org/questions/programming-9/stuck-on-sript-to-scp-a-file-548397/)

nazs 04-23-2007 05:12 PM

Stuck on script to scp a file
 
Hi All,
I am doing what you guys probably think a pretty basic script. I am just not that good at it yet. And I am sure mine is 3 times longer than it should be but i am stuck. I have to scp a file to another server. And then some how slogin to that server and continue a few more lines in the script. I have exchanged keys and can slogin without needing a password. It will login to the other server but the script will not continue to run after that. Is there a command to make it continue? This is my script below.

#!/bin/sh

pos=/usr/pa/archive/warner/rodanthe/pos

archive=/usr/pa/archive/warner/vrodanth/pos/archive

dest=/usr/pa/archive/warner/vrodanth/pos/rodanth

cd "$pos"

gunzip 1455*

for file in 1455*
do
cp "$file" "$dest/${file%%-*}"

gzip 1455*

mv "$pospay"/*.gz "$archive"

cd "$dest"

scp 1455* abcd@xfer.whatever.com:/home/wfs

slogin abcd@xfer.whatever.com

touch cur_dump.rodanth

echo "1455"* >> cur_dump.rodanth

done

Also after the last line echo "1455"* >> cur_dump.rodanthi need to call another script that is on the server i slogged onto. How would i do that?

Thanks,
Nazs

Tinkster 04-23-2007 07:27 PM

Code:

touch cur_dump.rodanth

echo "1455"* >> cur_dump.rodanth

Are you trying to execute these on the target machine?



Cheers,
Tink

nazs 04-23-2007 07:37 PM

Yes I am.
But once it slog's into the other machine it will not go any further.

Nazs

matthewg42 04-23-2007 08:25 PM

You could execute individual commands on the remote machine using:
Code:

ssh remotehost command
Make sure you escape wild-cards to stop your local shell expanding them. You can quote multiple commands and separate them with semi-colons. i.e. for your script:
Code:

ssh abcd@xfer.whatever.com 'touch cur_dump.rodanth ; echo "1455"* >> cur_dump.rodanth'

nazs 04-24-2007 09:51 AM

Thanks Matthew. I will give this a try today.

nazs 04-24-2007 05:30 PM

I modified the script and everything runs good till the very last command. The last command is to call another script to run on the remote machine it has logged onto. This is the error it gives me: bad interpreter: No such file or directory: /bin/sh

I will paste the update script below and mark in red the place the script stops.

#!/bin/sh

pos=/usr/pa/archive/warner/rodanthe/pos

archive=/usr/pa/archive/warner/vrodanth/pos/archive

dest=/usr/pa/archive/warner/vrodanth/pos/rodanth

cd "$pos"

#CHECK IF THERE ARE ANY POSITIVE PAY FILES
if [ `find . -type f -maxdepth 1 -name "1455*" | wc -l` -eq 0 ]; then
echo "Exit NO FILES"
exit
else

gunzip 1455*

for file in 1455*
do
cp "$file" "$dest/${file%%-*}"

gzip 1455*

mv "$pospay"/*.gz "$archive"

cd "$dest"

scp 1455* abcd@xfer.whatever.com:/home/wfs

slogin abcd@xfer.whatever.com "touch cur_dump.rodanth;echo "1455"* >> cur_dump.rodanth;/home/abcd/remote-script"

done
fi

Thanks,
Nazs

Tinkster 04-24-2007 05:39 PM

Does the script work when you manually run it on the remote
machine while you're logged in?


Cheers,
Tink

nazs 04-24-2007 06:02 PM

Hi Tinkster,
I just tried to run that script manually on the remote machine. I received the same error: bad interpreter: No such file or directory

Not sure what that exactly means.

Nazs

Tinkster 04-24-2007 06:06 PM

It could mean that there's no such file or directory, or that
you don't have permissions to run it. Check /bin to see whether
the is a sh
ls -l sh*


Cheers,
Tink

nazs 04-24-2007 06:11 PM

ls -l sh*
-rwxr-xr-x 1 root root 616312 Dec 6 2004 sh

The script is not being run by root. Is there a permision problem?

Nazs

matthewg42 04-24-2007 06:19 PM

ssh, not slogin


All times are GMT -5. The time now is 06:09 AM.