Sponsored Content
Top Forums Shell Programming and Scripting Make expect exit the UNIX script in erreneous condition Post 302963394 by ashima jain on Wednesday 30th of December 2015 02:37:12 AM
Old 12-30-2015
Sorry for the incomplete code. I had sent fragments of my code and hence only awk was present.

Code:
#!/bin/bash
#!/bin/expect -f

#set user [lindex $argv 0]
#set pswd [lindex $argv 1]

INTSRVUSR=$1;export INTSRVUSR
CGCUSERID=$2;export CGCUSERID
CGCPASS=$3;export CGCPASS
LABIP=$4;export LABIP
LABUSERID=$5;export LABUSERID
LABPASS=$6;export LABPASS
CURRENTDIR=`pwd`;export CURRENTDIR
FNAME="command";export FNAME

scptocgc(){
    ###---------------- scping the command file to the cgcuser
    expect -c '
    ##set timeout 10
   spawn scp -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no  $env(CURRENTDIR)/AUTOBnR/other_scripts/$env(FNAME) $env(CGCUSERID)@$env(INTSRVUSR):.

   expect "assword:"
   send "$env(CGCPASS)\r"
   expect {
   "directory" {
                send "touch ~/errorfile"; ## It doesn't touch the file here. It 
                                                        breaks the expect script. But how 
                                                        But I have to check at the end of 
                                                         the file whether the operation got 
                                                          completed or faced an error
                return error;
                }
   "ecamolx1820" {
                send "touch ~/filesent";
                 }
        }
        sleep 1
        ###---------------- login in to the cgcuser
        spawn ssh -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no $env(CGCUSERID)@$env(INTSRVUSR)
        expect -nocase "assword:"
        send "$env(CGCPASS)\r"
        '
   if  [ -f ~/error >/dev/null ]
    then
        echo "We faced some error"
    else
        echo "no error faced";
    fi
 }

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

check exit status - Expect Script

from my main script, i am calling an expect script. there are a lot of conditions in the Expect script and it can have any exit value based on success or failure of the Expect Script. how can i check the exit status of Expect scritp in the main script. (1 Reply)
Discussion started by: iamcool
1 Replies

2. Shell Programming and Scripting

Exit for loop in a shell script if a condition is successfull

Hi All, I am stuch in a script where a for loop is running to execute some commands for some values. Now my problem is i have to have an if condition that if the first iteration is successful then it has to exit the for loop otherwise it has to continue normally. my code is this: for... (5 Replies)
Discussion started by: usha rao
5 Replies

3. Shell Programming and Scripting

expect wait --More-- string and exit

Hi I am programing a expect script on debian, I connected to a firewall to get configuration copy via telnet or ssh but Because of firewall show configuration console wait and print --More-- need press space key at least 100.Help me please. firewall output like this :( This output isn't... (3 Replies)
Discussion started by: ayucelen
3 Replies

4. Shell Programming and Scripting

Expect script: obtain the exit code of remote command

Hi all, I'm trying to run the sipp simulator in crontab but after some attempt I came to the conclusion that for some reason this isn't possible (maybe due to sipp interactive nature). This is confirmed by these posts. Now I'm trying to launch sipp from an expect script that runs in crontab. ... (0 Replies)
Discussion started by: Evan
0 Replies

5. Shell Programming and Scripting

do nothing if condition is not met but not exit

Hello all, I created the below script....and it seemed to be working fine. My problem is i want the script to ignore rest of the things if my condition is not met but do not exit.... #!/bin/ksh ########################### ########################### # Set name of the listener, this... (2 Replies)
Discussion started by: abdul.irfan2
2 Replies

6. Shell Programming and Scripting

expect ssh script cannot finish and exit

All i am new to linux, and try to have a simple expect script to ssh then telnet to the network equipment, and exit itself. but dont know why i hang at the last $ #!/usr/bin/expect set timeout 10 set arg set arg1 spawn ssh -l UserA 1.1.1.1 expect "assword:"; send "PasSwOrD\r";... (1 Reply)
Discussion started by: samoptimus
1 Replies

7. Shell Programming and Scripting

Handle occasional condition in expect script

Hi, I am using Solaris OS, I want to handle an occasional expression in expect script while logging into a remote server with ssh. In normal scenario the expected expression is as below, spawn ssh $user@$ip expect "assword:" send "$password\r" but in a condition when the remote server... (2 Replies)
Discussion started by: varunksharma87
2 Replies

8. UNIX for Dummies Questions & Answers

Problem in Unix script to exit from Putty

We have a requirement where in the user needs to select a option 4 from the menu and the putty window should be closed.I tried giving exit 0 ;; and this is only exiting from the script menu and showing back the prompt.Is there a way for this. (2 Replies)
Discussion started by: gopalt
2 Replies

9. Shell Programming and Scripting

Time condition exit loop

Hi All, Requirement: The below script should automatically exit at 6pm everyday without manually killing the script Tried running with the below shell script but found the script was still running when the time was 6:15pm. The script did not exit the while loop at 6pm The script runs... (6 Replies)
Discussion started by: a1_win
6 Replies

10. Shell Programming and Scripting

How to exit from shell script if above condition fails?

HI cd ${back_home} if above back_home does not exist, then script shoul exit. Please let us know how to do that (7 Replies)
Discussion started by: buzzme
7 Replies
XINIT(1)						      General Commands Manual							  XINIT(1)

NAME
xinit - X Window System initializer SYNOPSIS
xinit [ [ client ] options ] [ -- [ server ] [ display ] options ] DESCRIPTION
The xinit program is used to start the X Window System server and a first client program on systems that cannot start X directly from /etc/init or in environments that use multiple window systems. When this first client exits, xinit will kill the X server and then termi- nate. If no specific client program is given on the command line, xinit will look for a file in the user's home directory called .xinitrc to run as a shell script to start up client programs. If no such file exists, xinit will use the following as a default: xterm -geometry +1+1 -n login -display :0 If no specific server program is given on the command line, xinit will look for a file in the user's home directory called .xserverrc to run as a shell script to start up the server. If no such file exists, xinit will use the following as a default: X :0 Note that this assumes that there is a program named X in the current search path. However, servers are usually named Xdisplaytype where displaytype is the type of graphics display which is driven by this server. The site administrator should, therefore, make a link to the appropriate type of server on the machine, or create a shell script that runs xinit with the appropriate server. Note, when using a .xserverrc script be sure to ``exec'' the real X server. Failing to do this can make the X server slow to start and exit. For example: exec Xdisplaytype An important point is that programs which are run by .xinitrc should be run in the background if they do not exit right away, so that they don't prevent other programs from starting up. However, the last long-lived program started (usually a window manager or terminal emula- tor) should be left in the foreground so that the script won't exit (which indicates that the user is done and that xinit should exit). An alternate client and/or server may be specified on the command line. The desired client program and its arguments should be given as the first command line arguments to xinit. To specify a particular server command line, append a double dash (--) to the xinit command line (after any client and arguments) followed by the desired server command. Both the client program name and the server program name must begin with a slash (/) or a period (.). Otherwise, they are treated as an arguments to be appended to their respective startup lines. This makes it possible to add arguments (for example, foreground and back- ground colors) without having to retype the whole command line. If an explicit server name is not given and the first argument following the double dash (--) is a colon followed by a digit, xinit will use that number as the display number instead of zero. All remaining arguments are appended to the server command line. EXAMPLES
Below are several examples of how command line arguments in xinit are used. xinit This will start up a server named X and run the user's .xinitrc, if it exists, or else start an xterm. xinit -- /usr/X11R6/bin/Xqdss :1 This is how one could start a specific type of server on an alternate display. xinit -geometry =80x65+10+10 -fn 8x13 -j -fg white -bg navy This will start up a server named X, and will append the given arguments to the default xterm command. It will ignore .xinitrc. xinit -e widgets -- ./Xsun -l -c This will use the command .Xsun -l -c to start the server and will append the arguments -e widgets to the default xterm command. xinit /usr/ucb/rsh fasthost cpupig -display ws:1 -- :1 -a 2 -t 5 This will start a server named X on display 1 with the arguments -a 2 -t 5. It will then start a remote shell on the machine fasthost in which it will run the command cpupig, telling it to display back on the local workstation. Below is a sample .xinitrc that starts a clock, several terminals, and leaves the window manager running as the ``last'' application. Assuming that the window manager has been configured properly, the user then chooses the ``Exit'' menu item to shut down X. xrdb -load $HOME/.Xresources xsetroot -solid gray & xclock -g 50x50-0+0 -bw 0 & xload -g 50x50-50+0 -bw 0 & xterm -g 80x24+0+0 & xterm -g 80x24+0-0 & twm Sites that want to create a common startup environment could simply create a default .xinitrc that references a site-wide startup file: #!/bin/sh . /usr/local/lib/site.xinitrc Another approach is to write a script that starts xinit with a specific shell script. Such scripts are usually named x11, xstart, or startx and are a convenient way to provide a simple interface for novice users: #!/bin/sh xinit /usr/local/lib/site.xinitrc -- /usr/X11R6/bin/X bc ENVIRONMENT VARIABLES
DISPLAY This variable gets set to the name of the display to which clients should connect. XINITRC This variable specifies an init file containing shell commands to start up the initial windows. By default, .xinitrc in the home directory will be used. FILES
.xinitrc default client script xterm client to run if .xinitrc does not exist .xserverrc default server script X server to run if .xserverrc does not exist SEE ALSO
X(7x), startx(1), Xserver(1), xterm(1) AUTHOR
Bob Scheifler, MIT Laboratory for Computer Science X Version 11 Release 6.6 XINIT(1)
All times are GMT -4. The time now is 09:06 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy