Your description is a little confusing. I need some clarification:
- You have a set of commands you need to run on a production machine as user 'superuser' (ie, userid 0)
- You can do this interactively by
- logging onto the production machine as yourself
- executing 'sudo su superuser'
- executing the commands
- You have attempted to write a perl script to connect to the production machine and do this, but cannot figure out the logic
it would be helpful if you provided a sample of what you've tried in Net::SSH::Expect. I have made a lot of assumptions here, but if they are correct, it boils down to attempting to execute the commands as 'superuser'. The easiest way I can think of to do this would be something like:
#! /usr/bin/perl
use strict;
use warnings;
use Fcntl qw( :mode );
# other code here...
my $file = "/tmp/su.cmds";
open (CMDS, ">$file");
print CMDS "#! /bin/bash\n";
print CMDS "command 1\n";
print CMDS "command 2\n";
close CMDS;
chmod S_IRWXU | S_IXGRP | S_IXOTH, $file;
system ("sudo superuser $file");
# script continues
This script obviously assumes you can run a perl script on the target system. You could just as easily do these using 'shell commands' via Expect (ie create a command file and use 'sudo superuser cmdfile' to run it).
fnord
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.