ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I need a bash script wich connects from my debian server to another debain server via ssh. Changes there to root and executes a pg_dump command. Afterwards the script should copie the file via scp back on my debian server where it schould be renamed with the actual date.
I know the single commands but I don't know how to get it in a bash script. (especially the ssh and root password)
First you need to setup key based ssh authentication. From the first server, run the command
"ssh-keygen -t rsa" as root. Hit enter when it asks you for a passphrase. It will generate two files in "/root/.ssh". Copy "/root/.ssh/id_rsa.pub" over to the other server, and rename it to "/root/.ssh/authorized_keys". Then verify that you can ssh to the server without typing the password.
Then, you can run commands on the other server by passing them as options to ssh. The output of the commands can be piped to files, and those files will be stored on the server you run the ssh command on.
I have a little Problem with this script again. I inserted the commands for openVPNc and it works fine when I run it manually. But if I want to run the script through a cronjob it creates the file but without any content. I only get the following error:
Code:
vpnc-connect: command not found
I don`t understand this error, because the script works fine, when I manually run it from the same user.
Can anyone help me?
Code:
#!/bin/bash
#
# this script is for database backup
#
# start VPN
vpnc-connect /etc/vpnc/nslu2_2.conf
# backup process
backupfile=/home/m/backup/printerdb-$(date +%d-%m-%Y).backup
ssh user@server pg_dump printerdb >$backupfile
# cleanup process
find /home/m/backup/ -mtime +21 -exec rm -r {} \;
# stop VPN
vpnc-disconnect
Make sure you include full path to your binaries such as vpnc-connect, find, and vpnc-disconnect in your script when running it as a cronjob as cron env is very limited.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.