![]() |
Return value to shell in script
Hi all, my problem today is that i am trying to do a smart upgrade which SOMETIMES requires an input of y or n to upgrade the packages. I want this inside a script but am unsure on how to return the value when it calls for it. Obviously it will require an if statement to say if it requires a command give it the value. Someone mentioned the expect statement so I looked into that and I think it will look something like
expect "y/n" send "y" But the problem is if you do a smart upgrade it will ask for yes or no while its performing the upgrade so putting smart upgrade expect "y/n" send "y" isnt really going to work because it will execute the expect command after the smart upgrade has finished. Does anyone know how to get round this? Thanks in advance. |
is the y/n entered by the user? if so
try Code:
echo -ne "Do you want to upgrade? (y/n):" |
When you "smart upgrade" if there any new packages it says "Confirm changes? (Y/n):" and expects a "y" or "n" to confirm changes. As I am trying to upgrade automatically every hour I want my script to reply "y" when it asks it to confirm changes. What I am trying to do is find a method that would do this sort of thing
If smart upgrade = "Confirm changes? (Y/n):" then return "y/r" Thanks. |
Any ideas anyone?
*bump* |
Quote:
Is it really so difficult to check for updates once a day manually? Isn't 1/hour a bit excessive? If not it is your system and you can do what you wish but I for one will not help you... If I am misunderstanding what a "Smart upgrade" is do please tell. |
Smart just downloads the latest updates, fixes dependencies and generally makes it a hell of a lot easier to install things. I suppose once an hour is a bit excessive but I want to make sure my system is up to date and I can't guarentee what time I'll be on linux. I'm sure there is a way of updating when you boot up, that will do. It isn't difficult to check manually every day for updates but it is a good training excercise to be able to do it. Thanks anyway, I'll wait for my books :) :study:
|
Quote:
I will say that 'expect' does seem to be exactly what you need. Have you read the documentation yet? From what you have written it seems you think of expect as a 'command' that you can use, but rather it is like a scripting language used to automate tasks that need user-intervention (like the spot you find yourself in). Without knowing the specific of your smart update program I can't help much but perhaps this page will get you started with expect: http://www.csc.calpoly.edu/~dbutler/.../tutorial.html |
With that tutorial I nearly had it, the problem being suse doesn't accept the spawn command. So when I execute my script...
Code:
#!./expect -f |
There's nothing wrong with spawn and SUSE, you just got something wrong there.
|
mwade:~ # spawn
-bash: spawn: command not found Code:
#!./expect -f |
Try and invoke expect with the -d switch, it will tell you what's going on. I believe that the expect command will time out before smart asks for a confirmation, so inserting "set timeout -1" into your script should help.
|
Aha! I've found a way of doing it.
Code:
yes '' | smart upgradeCode:
yes '' | smart upgrade > /usr/local/logs/outputfile.txt |
| All times are GMT -5. The time now is 12:35 AM. |