Has anyone used the "expect" in a script?

Hi all,
I’m trying to write a bash function to do dist- upgrades. So instead of typing

apt-get update
apt-get dist-upgrade -f -m -y 
apt-get autoremove --purge -y 
apt-get clean
apt-get update

I would just have to type a function name “update-everything()” which would look like this:

function upgrade_me{
apt-get update && apt-get dist-upgrade -f -m -y && apt-get autoremove --purge -y && apt-get clean && apt-get update
if{ needsrestart = 1
prompt= okay } fi
}

It was suggested I use the expect command to get the prompts handled but the needsrestart outputs two things, either OK or Close so now I’m unsure if I could do something like expect OK ||Closein my function (the man page isn’t very clear on that).
Thanks for any advice, if I can get this to work I can make it a Cron Job that runs everyday at 01:00 or something. My apticron runs everyday at 00:05 so I’d want to make sure they both don’t run at the same time.

If you have access to Ansible, I would suggest using that over expect. expect is great, but Anisible is much better, and there is a module for doing apt updates & things like that.

1 Like

I’ll look into it, I thought it might be too much for one machine.
Thanks for the suggestion.

1 Like