#!/usr/bin/perl use diagnostics; use warnings; use strict; use Expect; use CGI::Carp qw( fatalsToBrowser ); $|=1; print "Content-type: text/html\n\n"; my $timeout = 10; my $user = "mysqladmin"; my $pass = "mysqlpassword"; my $database = "items"; my $backup_path = '/tmp/b2.sql'; my $su_user = "anotheruser"; my $su_password = "password"; # Build su command and env my $cmd = "su -s /bin/sh"; my $run = "$cmd $su_user -c \"mysqldump -v -u $user --password=$pass $database > $backup_path\""; # Check output on screen - remove when live. print $run; print "
"; my $exp = Expect->spawn($run) or die "Cannot spawn command \n"; $exp->expect($timeout, ["Password:"]); $exp->send("$su_password\n");