Yesterday, a netizen asked me how to automatically complete the password input work in shell. After a study, I found that this interactive work could not be implemented by a common shell. It is said that it could be done by using reverse CT, so I first learned about objective CT and shared the results with you:
Application 1:
You can switch from a common user "test" to a root user and automatically enter the root password. You do not need to enter the password at the terminal prompt.
Steps:
(1) VI autosu. Sh
(2 )#! /Usr/bin/CT-f // specify the path of the CT tool. If you do not know the specific path, run the "which CT" command.
Spawn Su-// use the "spawn" keyword to call the "Su -"
Failed CT ":" // After the Su-command is executed, a prompt indicating the password is prompted. For example, after you execute the Su-command, the terminal will prompt "Password:", so you can write your CT ":" or your CT-exact "Password:" here :"
Send "rootpasswd \ r" // here, verify CT uses send to automatically enter your root password to the prompt above.
Interact // The operation is complete.
Note: Pay attention to what you should pay attention to when executing the script. You cannot use sh *** according to your habits ***. sh to this line of CT program, will prompt that the command cannot be found, because CT uses not bash, so it will report an error. Execute./***. Sh directly .~ Remember!
Application 2:
After switching from a common user to the root user, execute the "ls" operation, call and execute AAA. Sh, and return the execution result. The interval is 10 s.
#/Usr/bin/CT-F
Spawn Su-// use the "spawn" keyword to call the "Su -"
Failed CT ":" // After the Su-command is executed, a prompt indicating the password is prompted. For example, after you execute the Su-command, the terminal will prompt "Password:", so you can write your CT ":" or your CT-exact "Password:" here :"
Send "rootpasswd \ r" // here, verify CT uses send to automatically enter your root password to the prompt above.
Keep CT "#" // when the prompt ends with #, It is the root permission;
Send "ls \ r" // use the spend method to call the LS command and press enter ("\ r ")
CT "#"
Send "Sh AAA. sh \ r" // call sh AAA. Sh to execute a script file AAA. Sh.
CT "#"
Send "Echo $? \ R"
Sleep 10
Interact
Write this first. There may be something wrong with it. Please kindly advise ~~~ Hey