Remotely creating a tar file via ssh

I'm not even sure I can do this, but I want to have a script that ssh's to another server and creates a tar file on the remote server.  Is that even possible?  Here's what I have been working with, which isn't very much because I can't figure out how to make it work.

Thanks in advance for any help!
David

#!/usr/bin/ksh

server=$1

ssh $server 'tar cvf $server.logs.tar.gz /opt/bmc/Patrol3/log/Patrol*'
LVL 1
David AldridgeAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

arnoldCommented:
Where do you want the file to end up?
To be compressed you are missing the z flag.
Not sure why you are including the v option...

The script/command you have needs to have a key/pair between the user under whose rights this script rubs and remote system

You might better off setting up the process as a cron job if the file is to be created locally.

If you want the file created on the remote system you need to modify the line as

ssh $server '/usr/bin/tar cf - /opt/bmc/Patrol3/log/Patrol' | /usr/bin/gzip -c > "/path/to/where/you/want/the/file/$server.logs.tgz"

If your tar include the compress, you could use the z (cfz) with the output directed into the file (cut out the |gzip -c
..

The same issue, the user and credential gave to use use keys, or it will become an interactive requiring a password.

IMHO, using ssh_PASSWD env variable is not ...since that variable has to be defined......

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
David AldridgeAuthor Commented:
Modified your answer slightly by putting it in the background on the remote server, but you were spot on.
Thanks!
David
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Shell Scripting

From novice to tech pro — start learning today.