Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

running perl remotely via ssh

Status
Not open for further replies.

f0rmat

IS-IT--Management
Jun 2, 2004
102
US
Hi all,
I have a small problem that I've half solved.

I have 12 files, across 4 servers that I need to edit. I only need to change a single value in them and I thought perl would do nicely.

Here's what I have..
12 files containing the following

$maintenance = 0;
$debug = 0;
$sendMail = 0;
$showErrors = 1;

I need to set $maintenance = 1;

I recently learned about perls "-p" switch that allows you to edit.. so I wanted to use that as such below..

ssh -l webmaster chewbacca "perl -pi -e 's/\$maintenance \= 0\;/\$maintenance \= 1\;/g' /tmp/derek/cgifile.cgi"

where im logging into machine "chewbacca" as webmaster. I'm escaping all of the funny characters with \ and the end result that I see is everything is getting changed to 1, instead of just maintenance. Where did I steer wrong?

 
I would go with a regular expression, as I'm not if all files have would same type of spacing/characters.
 
You need to use \\\$maintenance in your replacement expression. Only one slash protects it from the shell, but not from perl itself, which tries to use contents of the variable $maintenance as the value to search for. If you add a -w to your perl command-line you'll see the "undefined variable" warnings.

Annihilannic.
 
\\\$maintenance worked great. Thanks a bunch!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top