1

I have a little script. It's ripped out of a Youtube tutorial, untested, ugly, and not very good. It's not done and not intended for public use. Here it is:

#!/bin/bash

sudo apt-get -y install git g++ gcc-multilib g++-multilib libc6-dev-i386 lib32z1-dev lib32bz2-dev xserver-xorg-dev:i386 libfreetype6-dev:i386 libmirclient-dev:i386 libosmesa6:i386 libosmesa-dev libjpeg-turbo8-dev:i386 libgl1-mesa-dev:i386 libglu1-mesa-dev:i386 libxcursor-dev:i386 libxi-dev:i386 libxrandr-dev:i386 libxinerama-dev:i386 libxcomposite-dev:i386 libdbus-1-dev:i386 libgnutls-dev:i386 libncurses5-dev:i386 libsane-dev:i386 libv4l-dev:i386 libgphoto2-6-dev:i386 liblcms2-dev:i386 liblcms1-dev:i386 gstreamer0.10-plugins-base:i386 libcapi20-dev:i386 libcups2-dev:i386 libfontconfig1-dev:i386 libgsm1-dev:i386 libtiff5-dev:i386 libmpg123-dev:i386 libopenal-dev:i386 libxrender-dev:i386 libxml2-dev:i386 libxslt1-dev:i386 libpng12-dev:i386 libssl-dev:i386 libldap2-dev:i386 unixodbc-dev:i386

sudo apt-get -y build-dep wine1.7

cd /usr/lib/i386-linux-gnu
sudo ln -s libfreetype.so.6 libfreetype.so
sudo ln -s libOSMesa.so.6 libOSMesa.so

git clone git://source.winehq.org/git/wine.git ~/wine-git
cd ~/wine-git

cat "/home/krabica/Dokumenty/TextFiles/0099-EndlessSpace-WGL-ShareList-Hack.patch" | patch -p1

./configure
make

I warned you.

As you can see, this script calls several commands, some as root and some as the normal user, in this case "krabica" ("box" (as in "cardboard box") in english).

The problem is that it takes 2+ hours to compile Wine on my laptop, so want to leave it running while I go to sleep, but I want my laptop to turn off/sleep or anything (enter a state where the computer and the fan doesn't work, to save energy and let me sleep in silence).

The problem is the shutdown must be called as sudo, or it won't work. But, at the time the script finishes, the password is no longer in the cache, and you need to type it again (not very convinient when you're asleep).

I tried to run path/to/script && sudo shutdown, but that didn't work either. It wants a password 15 minutes since you last typed it.

Is there any easy way to achieve this? By easy I mean not changing system settings, etc.

Thanks.

2
  • 1
    You don't need sudo for this, look at this answer askubuntu.com/a/201327/265974
    – TuKsn
    Jun 29, 2014 at 12:54
  • Ah, thanks for that. I did see the HAL version, but that didn't work. Jun 29, 2014 at 16:22

1 Answer 1

3

Wrap it up in a subshell:

sudo sh -c "/path/to/script; shutdown -h now"

The problem there is the script will run as root too. This might not be an issue (consider it in your case) but you can work around this by using sudo again to break back down to your $USER (which will be replaced because we're using double-quotes):

sudo sh -c "sudo -u $USER /path/to/script; shutdown"

It's a bit hacky but it should work.

2
  • Nice. Will definitely try it next time I compile. I learned something new today. Great thanks. Jun 29, 2014 at 16:24
  • Works perfectly. Thanks a lot! Although it should be noted that closing the terminal while this command is running (e.g. if you used sleep) turns off the computer too. Jul 9, 2014 at 19:32

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .