Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

125
Views
How do I run a command remotely as root ?

I`m trying to login to a server as userA then switch to the root account and run some command. The steps should be like:

  1. ssh userA@10.0.0.1
  2. su - root
  3. whoami

I implemented step 1 with the code below but don't know how to implement steps 2 and 3.

#!/usr/bin/expect -f
set timeout 12
set password_root 12345678
set password_A 12345678

spawn ssh -t sflow@10.0.0.1
expect -re ".*password:"
send "$password_sflow\r"
expect eof
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

#!/usr/bin/expect
set timeout 12
set password_root 12345678
set password_A 12345678

set prompt "#|>|\\\$ $"
spawn ssh -t user1@xxx.xxx.x.xx
expect  {
        timeout {puts TIMEOUT}
        "yes/no" {send "yes\r";exp_continue}
        "password:" {send "user1password\r";exp_continue}
        -re $prompt
}
send "su - root\r"
expect "Password:"
send "rootpassword\r"
expect -re $prompt
send "whoami\r"
expect -re $prompt

# and to exit
send "exit\r"      ;# exit su
expect -re $prompt
send "exit\r"      ;# exit ssh
expect eof
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!