Scripts To Respond To Prompts

I have searched and was unsuccessful in finding a quick command or example to use.

I'm looking to automate an update process using command line in Debian.
Normally I'd use apt-get update|upgrade|dist-upgrade .

If apt-get finds a package to update it queries a Y/n response.
My objective is to have a script determine if this prompt is there, and if so to respond with 'Y'.
If not then it should not enter a response.

I know I'll need to use an IF/ELSE function, but what I'm having difficulties locating is to read the output of apt-get .

I know there's books and sites available, but they are all long and sometimes difficult to read or understand. And maybe my keywords are the right ones to use, as I'm not able to pinpoint a solution.

Thanks for your assistance.


Similar Content



How To Return From Shell 'read' Command Passed In Expect Script?

I have a shell script that calls an expect script I wrote to ssh login to another host and get user input regarding that host's network configuration. I pass four arguments to the expect script: the remote host ip address, the username, the password, and the list of commands to run. My expect script is below:

#!/usr/bin/expect
# Usage: expectssh <host> <ssh user> <ssh password> <script>

set timeout 60
set prompt "(%|#|\\$) $"
set commands [lindex $argv 3];

spawn ssh [lindex $argv 1]@[lindex $argv 0]

expect {
"*assword:" {
send -- "[lindex $argv 2]\r"
expect -re "$prompt"
send -- "$commands\r"
}

"you sure you want to continue connecting" {
send -- "yes\r"
expect "*assword:"
send -- "[lindex $argv 2]\r"
expect -re "$prompt"
send -- "$commands\r"
}

timeout {
exit }

expect -re $prompt
send -- "exit\r"
}

The script runs well, except that if I send a command such as 'read' that requires user input, the script does not continue or exit after the user presses enter. It just hangs.

The commands I pass to the expect script and it's call are as follows:
SCRIPT='hostname > response.txt;netstat -rn;read net_card?"What is the network interface card number? " >> response.txt; read net_mask?"What is the subnet mask? " >> response.txt'

/usr/bin/expect ./expectssh.exp $hostip $usr $pswd "$SCRIPT"

Any suggestions on how I can pass a command to my expect script that requires user input without it hanging?

On a side note because I know it will come up - I am not allowed to do key-based automatic SSH login. I have to prompt for a username and password, which is done from my main shell script.

Thanks for any suggestions and help you can provide!

Update Grub Command Not Working

I have made a change to GRUB2 bootloader in etc/default/grub.
Now I need to run 'update grub' for the change to take effect.
However, the 'update grub' command on the terminal is giving this error message:
Code:
root@debian:/# update grub
bash: update: command not found

Can someone please explain why this command is no longer working?

I've had to make a change to grub because I tried to install a new distro which meant I had to alter grub.
The install wasn't successful so I deleted the grub file and then re-installed it.
The re-installed grub needs a change so I can get sound on my pc.
However, I can't add these changes because the 'update grub' command doesn't work.

I've checked the grub file with another debian distro and they are both the same.
So now I don't know if I need to check if a different grub file is the problem or anything else.
Can someone help?

No Space Left On Device When Doing Update.

I was trying to do an update using Update Manager and I got the error message:

No space left on device), E:IO Error saving source cache, E:The package lists or status file could not be parsed or opened.

I have attached a copy of my disk usage and it shows root as 100%. I thought that I had put the Home folder on it's own partition but I guess not.

I have also included the results of the ls -l command but fail to see what is using the space.

I am using LinuxMint Linux version 3.11-2-amd64 (debian-kernel@lists.debian.org) (gcc version 4.8.1 (Debian 4.8.1-10) ) #1 SMP Debian 3.11.8-1 (2013-11-13)

Thanks for your help in advance.

Regular Expression In Expect Script To Prevent Printing To Screen

Hello, I have an expect script where I ssh to a remote host to determine the network configuration and get from the user the network interface card that should be used. From their response, I determine the subnet mask and save the information to a text file that is later transmitted back to my local host. This is all so that I can set up virtual IP aliasing and verify that the physical IP address of the local and remote host are on the same subnet prior to continuing with the setup. I am running the script on Linux, with expect version 5.45.

The code itelf works just fine, but I'm having some issues with how it displays on the screen. As you'll see below in the example, the default system prompt displays, as does the user input command that I'm sending to the shell from the expect script.

Is there a regular expression or something that I can write to prevent the prompt and command that I'm sending from printing to the screen? I know that it should be suppressed if I have an expect command following the Code:
send -s "\nread n_card?'Enter the network interface card number for this server (i.e. eth0):   '\r

command, but everything I have tried for strings and regular expressions to expect causes the netstat -rn output to not show up all of a sudden. I'm new to expect, so I'm not really sure why this is happening.

I would really appreciate any help/suggestions. Thanks for your time!

Part of the Script Code:
Code:
expect {
   -re $prompt {   ;# Send individual commands and get user input
        set timeout -1
        
        # Get partner hostname and put in vipsetup.txt file
        send -s "hostname > vipsetup.txt\r"  
        expect -re $prompt
        
        # Display the network routing info for the user and prompt for 
        # network interface card number
        send -s "print \"The network routing table for the $ptner server is displayed below:\n\" ; netstat -rn \r"
        
        expect -re "\r(.*):\r"
        send -s "\nread n_card?'Enter the network interface card number for this server (i.e. eth0):   '\r"
        interact "\r" return    ;# Wait for user input from read command
        send -- "\r"
        send -s "echo \$n_card >> vipsetup.txt\r"  
        
        # Obtain subnet mask information for partner based on network 
        # interface card number being used
        send -s "msk=\$(cat /etc/sysconfig/network-scripts/ifcfg-\$n_card | grep NETMASK)\r"
        send -s "msk=\$(echo \${msk#NETMASK=})\r"
        send -s "echo \$msk >> vipsetup.txt\r"
    }
    timeout {
        send_user "Connection to host $hostip timed out."
        exit 6 
    }
    eof {
        send_user "Connection to host $hostip failed."
        exit
    }
}


Script Output:
Code:
The network routing table for the PRIMARY server is displayed below:
 
Kernel IP routing table
Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
10.105.65.0     0.0.0.0         255.255.255.0   U         0 0          0 eth0
0.0.0.0         10.105.65.1     0.0.0.0         UG        0 0          0 eth0
 [root@remotehost root]$
[root@remotehost root]$ ber for this server (i.e. eth0):   '              < 
Enter the network interface card number for this server (i.e. eth0):   eth0

Error With Unix Script

Hi,

I have a written a script:
Code:
#!/usr/bin/ksh
#--------------------------------------------------------------------------------------------------------------#
#qz='sqlplus barcqz/xdr56yhn@BARP2'
#wdc='sqlplus barcwdc/xdr56yhn@BARP2'
#--------------------------------------------------------------------------------------------------------------#
sqlplus barcqz/xdr56yhn@BARP2 <<EOF
update qz_dates set QZ_DT = sysdate;
update qz_dates_back set QZ_DT = sysdate;
update wdc_dates set WDCDATE = sysdate;
update WDC_PAY_EXRATE set WPESENTDATE = to_char(sysdate,'DD-MON-YY:HH:MI:SS') ;
update WDC_OU_STARTTIME set WOSBUSINESSDATE =sysdate;
commit;
exit
EOF

sqlplus barcwdc/xdr56yhn@BARP2 <<EOF
update WDC_PAY_EXRATE set WPESENTDATE=(substr(to_char(sysdate,'yyyy-mm-dd hh24:mi:ss'),1,10)||'T'||substr(to_char(sysdate,'yyyy-mm-dd hh24:mi:ss'),12,19));
commit;
exit
EOF

when i run this script on command prompt, it runs well, but when i schedule it in crontab, it gives an error as:

Code:
/devapp1_01/quartz/qzprod1/santosh/scripts/update_date.sh[6]: sqlplus:  not found.
/devapp1_01/quartz/qzprod1/santosh/scripts/update_date.sh[16]: sqlplus:  not found.
/devapp1_01/quartz/qzprod1/santosh/scripts/update_date.sh[6]: sqlplus:  not found.
/devapp1_01/quartz/qzprod1/santosh/scripts/update_date.sh[16]: sqlplus:  not found.

could someone please help on this?

Kill Zombie Process Via C Program Without Killing Main Process

Hi ,
In my program, for a process A executing operation, there are multiple threads created.
One of the thread A checks whether process is active or not
Second thread B executes a function
One of the periodic thread C calls a callback function that executes an audit after every 30 secs.

In the audit , the function uses g_spawn_commmand_line_sync() function to spawn a child process that executes a command line (shell script).

Since g_spawn_commmand_line_sync() spawns a new child process .
In the error case scenario, the spawned child process got stuck and became zombie process. It did not get killed.Also it acquired sockets which were assigned to a thread B executing operation.

Even though the thread B got terminated ,the child process did not release the sockets that were connected to it.


My question is ,I have to automate this in C program that if it finds spawned process of g_spawn_commmand_line_sync() defunct, the
health check thread B should be able to clean it without klling the main process.

i could not find any spawn function that will help me find the PID of g_spawn_commmand_line_sync() spawned process.

I get the details from ps commands. But how can I find it in a c-program?

Problem With Software Center

Hi
recently I installed elementary freya os
evey thing was ok with installing chrome ,qbittorent,ubuntu extras,vlc
but with virtual box I got this error
Package dependencies cannot be resolved
details

virtualbox-qt: Depends: libgcc1 (>= 1:4.1.1) but 1:4.9.1-0ubuntu1 is to be installed
Depends: libgl1 but it is a virtual package
Depends: libqt4-network (>= 4:4.5.3) but 4:4.8.5+git192-g085f851+dfsg-2ubuntu4 is to be installed
Depends: libqt4-opengl (>= 4:4.7.2) but 4:4.8.5+git192-g085f851+dfsg-2ubuntu4 is to be installed
Depends: libqtcore4 (>= 4:4.8.0) but 4:4.8.5+git192-g085f851+dfsg-2ubuntu4 is to be installed
Depends: libqtgui4 (>= 4:4.8.0) but 4:4.8.5+git192-g085f851+dfsg-2ubuntu4 is to be installed
Depends: libstdc++6 (>= 4.6) but 4.8.2-19ubuntu1 is to be installed
Depends: virtualbox (= 4.3.10-dfsg-1ubuntu5) but 4.3.10-dfsg-1ubuntu5 is to be installed

I tried apt-get update
apt-get upgrade and dist-upgrade & autoclen
and almost anything there
now even when trying to install any thing else it tells me there is broken packages !!!
it happend first with vlc
but apt-get update & autoclean solve it now it doesn't

Command Line IP Printing

Hi Forum,

I have a network printer (HP) running on 192.168.85.24 and I wish to install something that enables me to just shoot pdf och ps files directly to it from the command line, however, it has been hard finding something that describes how to make a bare bones setup like that, the most info I find talk about user interfaces, clicking menues opening web browsers etc, I want things incredibly simple, then they are more robust.

Do you have a tutorial on how to just get an HP-printer to accept ps och or pdf files from the command line?

I run Debian with LXDE and have contact with the printer. (I tested with ping.)

Another question I have is for this forum, do you have a search function? If I had had a search function I would have searched for an answer to the question before posting it.

Kind regards
Johnny

What Do I Do With This Huge Data On My Command Line Interface

Hi,

I have been trying to get information on how to process the output of a tcl file (aodv and leach protocol using mannasim) which I got on my command line Iinterface. Actually, I don't even know the keywords to search as I am new to this and other minor attempts haven't yielded positive results., I know there is usually a trace file but I can't see any. All I see is on my command line.

I also observe that it took the space on the entire screen and I can't copy the output from the start ( I could only copy from node 19 out of 30 nodes) because of the huge number of output lines.

The last thing I havent been able to figure ou is whether temperature is equivalent to energy Iin mannasim as mannasim has only temperature and carbon dioxide?


Thanks

Blackscreen Installing Debian Jessie Upgrading From Debian Wheezy

OK, I've created my user, I read all the post like: "Sticky: Please READ this before posting!" and the recommended post.

This morning I tried to upgrade my Debian Wheezy to Debian Jessie. I took a while to read the release-notes, change the source.list typing "jessie" in order of "wheezy".

Then, I opened a script with:

# script -t 2>~/actualiza-a-jessie01.time -a ~/actualiza-a-jessie01.script

and, finally:

# apt-get dist-upgrade

The installation started and all was go on until the postgresql when the installation stops and there was nothing to do. A lot of time after I decide restar the computer but now it doesn't start.

Appears the Debian 8 start menu with:
GNU GRUP versión 2.02

And the menu options:
Debian GNU/Linux
Opciones avanzadas para Debian GNU/Linux
Memory test (memtest86+)
Memory test (memtest86+, serial console 115200)
Memory test (memtest86+, experimental multiboot)
Memory test (memtest86+, serial console 115200, experimental multiboot)

When I select GNU/Linux I only get:
Loanding, please wait...
fsck from util-linux 2.25.2
/dev/sda1: clean, 619892/30269440 files, 68856006/121052672 blocks

and then.... nothing.

What can I do to restore my computer?

Thanks in advance.