Batch file sudo/su login

Microsoft WINDOWS XP
February 15, 2010 at 01:54:06
Specs: Windows XP, C2D/2GB
I want to create a DOS Batch file:
1. That login on 100 sun solaris/Unix servers.
2. search syslog.0, syslog.1, syslog.2...n so on
3. Then remove them.
To use RM command i have to login with SU.

Please help me to create that script.

I have already used a login script

@echo off
c:\Plink.exe -ssh -l xyz -pw "123456" -m input.txt >> result.txt

but i can not remove those file because to remove i have to login with "su".
and "su" can not login remotely.
i also unable to use sudo, because ask for password, I i dont know how to enter password in sudo script.

Please help

See More: Batch file sudo/su login

Report •

February 15, 2010 at 07:19:05
Same question was asked some time ago ... my advice is to ask the unix (in casu Solaris) admin to do his job properly.

Report •

February 15, 2010 at 10:02:26

I assume you are the administrator and
since you have to do this on 100 servers,
every day, you would rather automate ?

Let's build a solution for you step-by-step.

1. The solaris shell command to remove all
syslog.* files is

find "/" -name "syslog.*" -print -exec rm {} \;

2. To remove syslog files, you will need
to be superuser. You can NOT login as su
remotely, but you can supply
the supreuser password using a HERE DOCUMENT.
So, the solaris script is

su root << "EOF"
find "/" -name "syslog.*" -print -exec rm {} \;

3. If you put the above script in your DOS file
input.txt, and call the plink command as follows,
it will automate this for one server.

c:\Plink.exe -ssh -l xyz -pw "123456" -m input.txt >> result.txt

4. You now want to automate for
100 solaris servers (I assume that means
a lot of solaris servers).

Create a file C:/ServerList.txt as follows.\txyz\t123456\tsu_password

\t is tab.
First field is IP address of the solaris server,
second remote login,
third remote password,
fourth superuser password.
Each server entry - one per line.

5. Let's now write a biterscripting
( )
script to automate this for all Solaris servers
using the input from file C:/ServerList.txt.

# Script SolarisLogs.txt
var str list, serverentry, address, rlogin, rpswd, supswd, plinkcmd
set $wsep = "\t"
# Read server list.
cat "C:/ServerList.txt" > $list
# Get the first server entry.
lex "1" $list > $serverentry
# Process server entries one by one.
while ($serverentry <> "")
    # Extract the fields.
    wex -p "1" $serverentry > $address
    wex -p "2" $serverentry > $rlogin
    wex -p "3" $serverentry > $rpswd
    wex -p "4" $serverentry > $supswd

    # Compose the input.txt file.
    echo "su root << \"EOF\"" > input.txt
    echo $supswd >> input.txt
    echo "EOF" >> input.txt
    echo "find \"/\" -name \"syslog.*\" -print -exec rm {} \;" >> input.txt

    # Compose the plink command.
    set $plinkcmd="c:/Plink.exe -ssh -l "+$rlogin+" "+$address+" -pw \""+$rpswd+"\" -m input.txt >> result.txt"

    # Execute the plink.cmd.
    system -s $plinkcmd

    # Get the next server entry.
    lex "1" $list > $serverentry

6. Save this script in file
C:/Scripts/SolarisLogs.txt on your local
DOS system, from where you will kick off
this activity. You can now run this script
manually from biterscripting with this command.

script "C:/Scripts/SolarisLogs.txt"

7. Of course, you do not want to
run this manually every day. So,
schedule this script to run at a time daily
when the servers are least in use,
using cron or task scheduler,
with the following command.

"C:/biterScripting/biterScripting.exe" script "C:/Scripts/SolarisLogs.txt"

That completes the solition. It was a good
challenge. I have not tested it. You may need
to do some trial-and-error during testing.
But I hope that this, at least, provides a
good starting point.

And yes, if you improve upon this solution,
you should re-post it for the benefit of
other over-worked Solaris administrators.

Report •

February 15, 2010 at 10:07:57

One error in my above post. The cron or task scheduler command should be

"C:/biterScripting/biterScripting.exe" "C:/Scripts/SolarisLogs.txt"

You should not have the word script in that command.

Report •

Related Solutions

February 15, 2010 at 11:27:44

Report •

February 16, 2010 at 11:48:10
> I remember this one

Me too

Report •

February 18, 2010 at 23:47:59
Dear Sen Hu,

Thanks for your reply.

I want to use .bat or .vbs script only.

for this i have to learn "biterScripting".

Please provide me solution in .bat or .vbs....

Thanks in advance...

Report •

February 19, 2010 at 12:02:57
Yeah, one can only administer Linux if you know biterscript, all experts know that.

Report •

Ask Question