Sponsored Content
Top Forums Shell Programming and Scripting Passing a MySql password from bash script Post 302374575 by codenjanod on Wednesday 25th of November 2009 02:32:59 AM
Old 11-25-2009
Passing a MySql password from bash script

Hi all,

I am running this script on Mandrakelinux release 10.1, 2.6.8.1-12mdksmp #1 SMP
I have also installed 'expect' separately.

I have created an Rsync script, but before any Rsync command does run, a MySql dump must be done first, and I am battling a bit to pass the MySql password from the bash script.

This is what my script looks like:
Code:
#!/bin/bash

VAULT='backupserver'
RSYNC=`which rsync`
DATE=$(date +%Y-%m-%d.%H:%M)
LOG="/tmp/MySql-$DATE.log"
MYSQLDUMP='/usr/local/mysql/bin/mysqldump'
BACKUPDIR='/Data/Mysql_Backups'
PASS='/root/.credentials'

backup () {
    VAR=$(expect -c "
        spawn "$MYSQLDUMP -u root -p database_1 $BACKUPDIR/backup.sql"
        expect \"password:\"
        send \"$PASS\r\"
        expect \"\\\\$\"
    ")
    echo "==============="
    echo "$VAR" 

        $RSYNC -e ssh -avl --delete --stats --progress $BACKUPDIR/backup.sql    root@$VAULT:/vault2/Backups/MySql    >> $LOG
        rm -rf $BACKUPDIR/backup.sql
}

backup

The output I get when running the script is:
Quote:
expect: invalid option -- u
usage: expect [-div] [-c cmds] [[-f] cmdfile] [args]
===============
spawn /usr/local/mysql/bin/mysqldump
rsync: link_stat "/Data/Mysql_Backups/backup.sql" failed: No such file or directory (2)
rsync error: some files could not be transferred (code 23) at main.c(692)
Thanks for the help.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

passing variable from bash to perl from bash script

Hi All, I need to pass a variable to perl script from bash script, where in perl i am using if condition. Here is the cmd what i am using in perl FROM_DATE="06/05/2008" TO_DATE="07/05/2008" "perl -ne ' print if ( $_ >="$FROM_DATE" && $_ <= "$TO_DATE" ) ' filename" filename has... (10 Replies)
Discussion started by: arsidh
10 Replies

2. Shell Programming and Scripting

passing password in shell script

Hi, Anybody help to write a shell script as below requirement. script stops some costomized application services. 1. first it will stop apache as root 2. then it will switch to my application user and stop app service. Note: passing password is required to stop app service as app... (1 Reply)
Discussion started by: manojbarot1
1 Replies

3. Shell Programming and Scripting

ssh - passing password in shell script

I have a requirement, I need to run a command at remote system using a ssh. Is there any way we can pass the username and password in shell script to the ssh command as we did it in one of the shell script for FTP. ftp -n $i <<!EOF >> user Username $PASSWD cd /home/scripts ... (5 Replies)
Discussion started by: Muktesh
5 Replies

4. Shell Programming and Scripting

Passing a variable from shell script to mysql query?

I heard this was possible but from my research I haven't been able to figure it out yet. Seems it should be simple enough. Basically from a high level view I'm trying to accomplish... . $X='grep foo blah.log' then 'mysql command SELECT foo FROM bar WHERE ' . $X or something like that. ... (2 Replies)
Discussion started by: kero
2 Replies

5. Shell Programming and Scripting

passing database password to isql command in shell script

Hi, I need to connect to DB through my shell script. but I dont want to hardcode my db password in the script. Is there a way to do it? Thanks ---------- Post updated at 07:42 PM ---------- Previous update was at 04:54 PM ---------- :(Guys..please help me with this:( (1 Reply)
Discussion started by: agrawal.prachi
1 Replies

6. Shell Programming and Scripting

Passing password in script for ssh connection - no except

Used the script posted on forum - unix.com/shell-programming-scripting/21597-script-change-passwords-same-user-multiple-servers.html but the last question posted on this seems to be still unanswered, tried different things with no success, can someone help giving an way to pass the password via... (5 Replies)
Discussion started by: sapadmin
5 Replies

7. Shell Programming and Scripting

Passing Password to SSH without using expect in a Script

How can I pass password in SSH command without using expect in a shell program. I don't have expect installed on my Solaris server. #!/bin/bash ssh user@hotname (how to supply pass in script?:wall:) Experts please help its very urgent. Shrawan Kumar Sahu (4 Replies)
Discussion started by: ss135r
4 Replies

8. Shell Programming and Scripting

Passing password for ssh in Script

I want to do following 2 commands via script: 1) eval `ssh-agent`2) ssh-add /export/home/sufuser/.ssh/id_rsa When asked for passphrase enter "passwordpassword1234 but whenever I run the script it stucks after "ssh-add /export/home/sufuser/.ssh/id_rsa" command and asks fro... (4 Replies)
Discussion started by: yogeshpawar
4 Replies

9. Shell Programming and Scripting

Make a password protected bash script resist/refuse “bash -x” when the password is given

I want to give my long scripts to customer. The customer must not be able to read the scripts even if he has the password. The following command locks and unlocks the script but the set +x is simply ignored. The code: read -p 'Script: ' S && C=$S.crypt H='eval "$((dd if=$0 bs=1 skip=//|gpg... (7 Replies)
Discussion started by: frad
7 Replies

10. Shell Programming and Scripting

Expect script not passing password / commands ??

Newbie here. My goal is to have the expect script log into the Ubuntu 18.04 server and run two commands (lsb_release -a and ip addr) and eventually pipe the output/results to a file. For now, I would be happy to get this one command or two to run successfully. How to fix this? #!/usr/bin/expect ... (3 Replies)
Discussion started by: jacob600
3 Replies
BACKUPNINJA(1)							backupninja package						    BACKUPNINJA(1)

NAME
BACKUPNINJA - A lightweight, extensible meta-backup system "a silent flower blossom death strike to lost data." SYNOPSIS
backupninja [ -h ] [ -d ] [ -n ] [ -t ] [ -f filename ] [ --run filename ] DESCRIPTION
Backupninja allows you to coordinate system backups by dropping a few simple configuration files into /etc/backup.d/. Most programs you might use for making backups don't have their own configuration file format. Backupninja provides a centralized way to configure and coor- dinate many different backup utilities. FEATURES
- easy to read ini style configuration files. - you can drop in scripts to handle new types of backups. - backup actions can be scheduled. - you can choose when status report emails are mailed to you (always, on warning, on error, never). - console-based wizard (ninjahelper) makes it easy to create backup action configuration files. - passwords are never sent via the command line to helper programs. - in order to backup a db or sql database, you cannot simply copy database files. backupninja helps you safely export the data to a format which you can backup. - works with Linux-Vservers. Backup types include: - secure, remote, incremental filesytem backup (via rdiff-backup). incremental data is compressed. permissions are retained even with an unpriviledged backup user. - basic system and hardware information. - encrypted remote backups (via duplicity). - safe backup of MySQL, PostgreSQL, OpenLDAP, and subversion databases. - burn CD/DVDs or create ISOs. OPTIONS
-h, --help Show summary of options -d, --debug Run in debug mode, where all log messages are output to the current shell. -f, --conffile CONF_FILE Use CONF_FILE for the main configuration instead of /etc/backupninja.conf -t, --test Run in test mode, no actions are actually taken. -n, --now Perform actions now, instead of when they might be scheduled. --run ACTION_FILE Runs the action configuration ACTION_FILE and exits. CONFIGURATION
General settings are configured in /etc/backupninja.conf. In this file you can set the log level and change the default directory loca- tions. See backupninja.conf(5). To preform the actual backup actions, backupninja processes each action configuration file in /etc/backup.d according to the file's suffix. See backup.d(5). EXAMPLE USAGE
Backupninja can be used to implement whatever backup strategy you choose. It is intended, however, to be used like so: First, databases are safely copied or exported to /var/backups. Often, you cannot make a file backup of a database while it is in use, hence the need to use special tools to make a safe copy or export into /var/backups. Then, vital parts of the file system, including /var/backups, are nightly pushed to a remote, off-site, hard disk (using rdiff-backup). The local user is root, but the remote user is not privileged. Hopefully, the remote filesystem is encrypted. In order for this to work (ie for diff-backup to run unattended), you must create ssh keys on the source server and copy the public key to the remote user's authorized keys file. For example: root@srchost# ssh-keygen -t rsa -b 4096 root@srchost# ssh-copy-id -i /root/.ssh/id_dsa.pub backup@desthost Now, you should be able to ssh from user 'root' on srchost to user 'backup' on desthost without specifying a password. When prompted for a password by ssh-keygen, just leave it blank by hitting return. The "wizard" ninjahelper(1) will walk you through these steps. FILES
/usr/sbin/backupninja main script /etc/backupninja.conf main configuration file; general options /etc/cron.d/backupninja runs main script hourly /etc/logrotate.d/backupninja rotates backupninja.log /etc/backup.d directory for configuration files /usr/share/backupninja directory for handler scripts /usr/share/doc/backupninja/examples example action configuration files. SEE ALSO
ninjahelper(1), backupninja.conf(5), backup.d(5), AUTHOR
BACKUPNINJA was written by the riseup.net collective. riseup October 10, 2005 BACKUPNINJA(1)
All times are GMT -4. The time now is 08:54 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy