LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-11-2011, 04:03 PM   #1
metallica1973
Senior Member
 
Registered: Feb 2003
Location: Washington D.C
Posts: 2,190

Rep: Reputation: 60
Supressing output of function to stdout


I have a script that uses expect to backup and scp a mysql database. The scripts works well but does something that I do not want to happen. When I run the script and it gets to the expect and scp functions is displays everything including the password on the screen.

The functions:

Code:
## Functions using Expect##

ssh_mysql_bak()
{
expect <<EOD
spawn ssh -p 3202 testuser@10.7.0.105 "mysqldump --opt -u root -pmysqlpass mysql > mysql.bak.dump"
expect "testuser@10.7.0.105's password:"
send "MyPassword\r"
wait
EOD
}

scp_mysql_bak ()
{
expect <<EOD
spawn scp -P 3202 testuser@10.7.0.105:/home/testuser/mysql.bak.dump $home_dir
expect "testuser@10.7.0.105's password:"
send  "MyPassword\r"
wait
EOD  
}
section in my script where it is called:

Code:
ssh_mysql_bak && scp_mysql_bak;$search ./Downloads -iname mysql.bak.dump | $archive > /home/testuser/extract/mysql$date.cpio 2> /home/testuser/extract/mysql_status$date.log
and the output to the screen:

Code:
./ssh_scp.ksh full
spawn ssh -p 3202 testuser@10.7.0.105 mysqldump --opt -u root -pmysqlpass mysql > mysql.bak.dump
parent: waiting for sync byte
parent: telling child to go ahead
parent: now unsynchronized from child
spawn: returns {8908}

expect: does "" (spawn_id exp6) match glob pattern "testuser@10.7.0.105's password:"? no


############################ Welcome ######################################
testuser@10.7.0.105's password: 
expect: does "\r\n\r\n############################ Welcome ######################################\r\ntestuser@10.7.0.105's password: " (spawn_id exp6) match glob pattern "testuser@10.7.0.105's password:"? yes
expect: set expect_out(0,string) "testuser@10.7.0.105's password:"
expect: set expect_out(spawn_id) "exp6"
expect: set expect_out(buffer) "\r\n\r\n############################ Welcome ######################################\r\ntestadmin@10.7.0.32's password:"
send: sending "testuser\r" to { exp6 }
spawn scp -P 3202 testuser@10.7.0.105:/home/testuser/mysql.bak.dump /home/testuser/extract
parent: waiting for sync byte
parent: telling child to go ahead
parent: now unsynchronized from child
spawn: returns {8914}

expect: does "" (spawn_id exp6) match glob pattern "testadmin@10.7.0.32's password:"? no


############################ Welcome ######################################
testuser@10.7.0.105's password: 
expect: does "\r\n\r\n############################ Welcome ######################################\r\ntestuser@10.7.0.105's password: " (spawn_id exp6) match glob pattern "testuser@10.7.0.105's password:"? yes
expect: set expect_out(0,string) "testuser@10.7.0.105's password:"
expect: set expect_out(spawn_id) "exp6"
expect: set expect_out(buffer) "\r\n\r\n############################ Welcome ######################################\r\ntestuser@10.7.0.105's password:"
send: sending "testuser\r" to { exp6 }
how can I hide this stuff? I need to /dev/null somewhere ??

Last edited by metallica1973; 10-11-2011 at 04:13 PM.
 
Old 10-11-2011, 04:37 PM   #2
Snark1994
Senior Member
 
Registered: Sep 2010
Distribution: Debian
Posts: 1,632
Blog Entries: 3

Rep: Reputation: 346Reputation: 346Reputation: 346Reputation: 346
Adding ">/dev/null" should work, hopefully; like you redirected with

Code:
$archive > /home/testuser/extract/mysql$date.cpio
but to /dev/null.

Hope this helps,

Last edited by Snark1994; 10-11-2011 at 04:39 PM.
 
Old 10-11-2011, 04:53 PM   #3
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
Quote:
Originally Posted by metallica1973 View Post
Code:
spawn ssh -p 3202 testuser@10.7.0.105 "mysqldump --opt -u root -pmysqlpass mysql > mysql.bak.dump"
Not an exact answer to your question but if I may: I think you're making a design error here. There's absolutely no reason why you can't or shouldn't trigger a dump locally or remotely without requiring root SSH access for instance (there are alternatives) using Sudo, a simple shell script and a (passwordless) unprivileged user SSH key with host and command restrictions set. If the script then directs the dump to a location the same or another unprivileged SSH user can SCP or SFTP it from you wouldn't need root anyway which would be better given security best practices.

Press CTRL-Q if you are willing to think things over ;-p
 
Old 10-11-2011, 05:53 PM   #4
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
Quote:
Originally Posted by unSpawn View Post
Not an exact answer to your question but if I may: I think you're making a design error here. There's absolutely no reason why you can't or shouldn't trigger a dump locally or remotely without requiring root SSH access for instance (there are alternatives) using Sudo, a simple shell script and a (passwordless) unprivileged user SSH key with host and command restrictions set. If the script then directs the dump to a location the same or another unprivileged SSH user can SCP or SFTP it from you wouldn't need root anyway which would be better given security best practices.

Press CTRL-Q if you are willing to think things over ;-p
This looks like a MySQL username of "root", not a system username.
Kevin Barry
 
Old 10-11-2011, 06:48 PM   #5
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
Quote:
Originally Posted by ta0kira View Post
This looks like a MySQL username of "root", not a system username.
Thanks for correcting, you're right.
 
Old 10-11-2011, 07:11 PM   #6
metallica1973
Senior Member
 
Registered: Feb 2003
Location: Washington D.C
Posts: 2,190

Original Poster
Rep: Reputation: 60
Many thanks for all of your replies,

That was a good catch and I will see if I can use or create an addition account only for the purpose of this backup via a standard user account. I was given this task without much room to work with. The mysql database is on a hosted server at a remote location and the only account that was given to me was root along with root account on the mysql database. As far a suppressing the output,I can just drop a /dev/null somewhere, I just have to play around with it.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
bash output stderr to 2 files and stdout vascot Linux - Software 1 04-05-2011 08:04 AM
libxml2: removing output on stdout/stderr VincOx Programming 4 07-28-2010 02:40 AM
grep output on stdout and grep output to file don't match xnomad Linux - General 3 01-13-2007 04:56 AM
stdout & stderror output nevx Linux - Newbie 1 05-03-2005 06:56 AM
how to output stdout to a file SciYro Linux - Newbie 4 02-25-2004 05:08 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:50 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration