Sponsored Content
Top Forums Shell Programming and Scripting Windows Batch script for Unix commands Post 302713575 by mohtashims on Thursday 11th of October 2012 02:17:56 AM
Old 10-11-2012
Error

Quote:
Originally Posted by Corona688
plink can take the password as a parameter, you don't have to jam it into stdin.

You should be checking the commands you run for success or failure, anyway.
The problem with this is, I am using Soft Token and the random password gets generated every 1 minute and the same password cannot be used twice.

It uses the first password for login to unix server A, and then expect a new random generated password for unix server B which I am not sure how to pass using plink along with the mkdir command.

the ssh option with plink does not do anything different.

plink -ssh user1@244.60.212.17 -pw 724494

It logs me in to unix ServerA and then to unix ServerB where is prompts for the password. Then I am into the unix shell from my windows shell as seen in the snap below.

Image

http://imageshack.us/f/138/dosp.png/

In unix Server A home directory I see this mechanism to make it auto-switch to unix ServerB.

more .profile

Code:
echo "Connecting to: Server2"
exec /usr/local/bin/dev13
                exit
 
ls -ltra
-r-xr-xr-x 1 root root 2406 Feb  8  2012 /usr/local/bin/dev13

and below is the /usr/local/bin/dev13 file...

Code:
#!/bin/ksh
# $Header: /home/m37677/SOURCE/Server/RCS/dev13,v 1.16 2010/11/19 15:34:30 m37677 Exp $
touch $HOME/.lastlog
UNAME="$LOGNAME"
LANDHOST="dev13"
LANDTXT='Default (dev13)'
DATE=`date +%m%d%y%H%M`
LOG="$HOME/`basename $0`.log.$DATE"
PATH=$PATH:/usr/sbin
HOSTNAME="`hostname | awk -F. '{print $1}'`"
ALOG="/home1/logs/activity.log"
DLOG="/home1/logs/dactivity.log"
#function to do logging
LOGIT () {
FINISHED=`date +%d-%b-%y\ %T`
SFINISHED=`date +%m/%d/%Y\ %T`
echo "$LOGNAME|$HOST|$UNAME|$START|$FINISHED|$CMD|$FNAME|$TYPE|$SIZE|$HOSTNAME">>$ALOG
echo "$LOGNAME|$SRCIP|$DSTIP|$PORT|$UNAME|$START|$FINISHED|$CMD|$FNAME|$TYPE|$SIZE|$HOSTNAME">>$DLOG
echo "|$LOGNAME|$SRCIP|$DSTIP|$PORT|$UNAME|$SSTART|$SFINISHED|$CMD|$FNAME|$TYPE|$SIZE|$HOSTNAME" |logger -t SSHPT -p local5.info
}
#create activity log if it does not exsist
/usr/local/bin/Create_activity_log
let TT=`echo $LANDHOST |awk -F. '{print $1}'`/1 >/dev/null 2>&1
if [ $? -gt 0 ]; then
DSTIP="`nslookup $LANDHOST |grep Address |tail -1 |awk -F: '{print substr($2,2)}'`"
else
DSTIP=$LANDHOST
fi
unset TT
echo "STARTED: `date`" >$LOG
START=`date +%d-%b-%y\ %T`
SSTART=`date +%m/%d/%Y\ %T`
TIME=`date +%T`
if [ "`uname`" = "Linux" ];then 
SRCIP="`tail /var/adm/messages |grep $TIME | grep port |grep Accepted |tail -1|awk '{print $11\"|\"$13}' `"
else
SRCIP="`tail /var/log/messages |grep $TIME | grep port | awk '{print $11\"|\"$13}' |awk -F: '{print $4}' `"
SRCIP="`tail /var/log/messages |grep $TIME | grep port | awk '{print $11\"|\"$13}' |awk -F: '{print $4}' `"
SRCIP=`tail /var/adm/messages |grep $TIME | grep port | awk '{print $13\"|\"$15}' 2>/dev/null`
#Having problems capturing the log info from Sun.
if [ "$SRCIP" = "" ];then
SRCIP="`tail /var/adm/messages |grep $LOGNAME | grep port |tail -1 |awk '{print $14\"|\"$16}' `"
fi
fi
#if data is null use "|"
[ "$SRCIP" = "" ] && SRCIP="0.0.0.0|0"
#Log clean up
find $HOME -name "`basename $0`.$2.log.*" -mtime +5 -exec rm {} \; >/dev/null 2>&1 &
CMD="`basename $0`"
if [ -s /usr/localcw/opt/OPENssh/bin/ssh ];then
FNAME="N/A"
/usr/localcw/opt/OPENssh/bin/ssh -a -x $LANDHOST
fi
if [ -s /usr/bin/ssh ];then
echo "Session log = $LOG.session" >>$LOG
FNAME="$LOG.session"
/usr/bin/script -qc "/usr/bin/ssh -a -x $LANDHOST" $LOG.session 
fi
SIZE="N/A"
TYPE="N/A"
echo "FINISHED: `date`" >>$LOG
LOGIT

Is this what will help you help me :P

Last edited by mohtashims; 10-11-2012 at 07:43 AM..
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

How can I run scripts in my unix account from batch file in Windows?

Hi all, I'm working on Windows, connecting to my Unix account by different ways: by FTP opening files in UltraEdit32, by mapping drive to browse, by Exceed or Telnet to compile at Unix account. Actually, that is what I would like to change: I'd like to make a batch file which would connect to... (7 Replies)
Discussion started by: olgafb
7 Replies

2. Shell Programming and Scripting

how to convert unix .ksh script to windows .batch script

I am using awk in my .ksh script but when I am trying to run in windows its not recognising awk part of the ksh script , even when I changed it to gawk it does not work, this is how my .ksh and .bat files look like. thanx. #!/bin/ksh egrep -v "Rpt 038|PM$|Parameters:|Begin |Date: |End... (1 Reply)
Discussion started by: 2.5lt V8
1 Replies

3. Windows & DOS: Issues & Discussions

Windows services for unix - How do I run in batch

I just installed Windows Services for Unix. I want to create a ksh program and schedule it using the Windows scheduler. How would I go about doing it? What would the command line look like? Do I always have to be in a ksh shell to run the batch program even if it is not scheduled? ... (3 Replies)
Discussion started by: rbdenham
3 Replies

4. Shell Programming and Scripting

Executing Windows batch file from UNIX

Hi everyone, let me get straight to the points. My manager wants to execute a remote batch file (on a Windows server) from a UNIX Machine, does anyone know if this is possible and what packages would be needed? Thanks p.s. Sorry i cant give OS specifics, we use most UNIX's; AIX, Solaris,... (5 Replies)
Discussion started by: flip387
5 Replies

5. Shell Programming and Scripting

Change the Windows Batch script to UNIX shell script.

Hi, When I run the below script in UNIX it's throwing syntax errors. Actually it's a windows batch script. Could anyone change the below Windows Batch script to UNIX shell script... Script: REM :: File Name : Refresh_OTL.bat REM :: Parameters : %1 - Region REM :: : %2 - Cube Type REM ::... (5 Replies)
Discussion started by: tomailraj
5 Replies

6. Windows & DOS: Issues & Discussions

Check the file size using Batch script in windows

Hi, I need to check the file size using a batch script. Pls advise. (0 Replies)
Discussion started by: krackjack
0 Replies

7. Shell Programming and Scripting

Batch job in unix server to move the pdf file from unix to windows.

Hi Experts, I have a requirement where i need to setup a batch job which runs everymonth and move the pdf files from unix server to windows servers. Could some body provide the inputs for this. and also please provide the inputs on how to map the network dirve in the unix like that... (1 Reply)
Discussion started by: ger199901
1 Replies

8. Windows & DOS: Issues & Discussions

Gawk Script in Windows batch file - Help

Good morning all. I have been running into a problem running a simple gawk script that selects every third line from an input file and writes it to an output file. gawk "NR%3==0" FileIn > FileOut I am attempting to run this command from a batch file at the command line. I have several hundred... (6 Replies)
Discussion started by: 10000springs
6 Replies

9. Shell Programming and Scripting

To run a shell script in remote server from windows batch file

Hi all, i need to run a shell script on remote server. I have created file .bat file in windows server with following code, c:\Users\Desktop\putty.exe -ssh -pw password user@server ./script.sh i need to run the script.sh in my remote server Above command is not working, any... (4 Replies)
Discussion started by: rammm
4 Replies

10. Shell Programming and Scripting

Windows batch script to Shell script

Hi everyone, I've below windows batch script which is used to filter the file contents line by line and assign the matched values to the variables in for loop. for /F "tokens=1,3 delims=:" %%A in (%LOG_DIR%\PM_IS_workflow_status.log) do ( set "ATTR_NAME=%%A" if /i "!ATTR_NAME!" EQU "Folder"... (1 Reply)
Discussion started by: Kathraji
1 Replies
All times are GMT -4. The time now is 08:22 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy