2

How can I start Steam using a cron job?

I've tried just putting steam in cron, but it does not work. I've tried some odd stuff that I don't understand like DISPLAY=:0.0 steam %U but that does not work either.

I've tried these lines in cron:

00 02 * * * steam
00 02 * * * DISPLAY=:0.0 steam %U
00 02 * * * /usr/bin/steam %U

Also, is there a way to complete a Steam client update from a cron job? Usually a client update will require user input by asking for permission to restart before it will download and install a client update.

Additionally, if anyone knows how to STOP Steam from cron (as in cause a regular exit under Steam's terms like if you'd pressed "exit"; not a hard kill of the application) I would would also like to know that.

The reason is that I'm stuck with a lousy ISP with a data cap (Hughes.net = crap) except between 2AM-7AM and I'd like to be able to start Steam and get all game/client updates during that time. I know that under Steam/Settings/Downloads you can set it to only download game updates during a certain time but that would only work if I left my computer and Steam running all night; I have my computer's BIOS wake-on-timer set up to boot up my computer a little before 2AM, so I can't leave Steam running. Thank you!

6
  • Are you just putting Steam? Or are you entering /usr/share/steam.desktop when you add the cron job? I'm pretty sure you have to add the absolute path rather than just the name of the program. – Andrew Wallace Jun 30 '15 at 21:40
  • 1
    whats the command you want to run and when you want to run ? – heemayl Jun 30 '15 at 21:51
  • Thank you for the comments. I don't seem to have a file called /usr/share/steam.desktop. I don't know if that's related to the fact that I'm running Xubuntu instead of vanilla Ubuntu. I have tried "/usr/bin/steam %U" because that's the command that the Steam desktop shortcut says it is using, but it does not work in cron either. – InverseTelecine Jul 1 '15 at 0:34
  • The %U is something specific to .desktop files - for cases like when you drag and drop something on to a launcher, for example. The cron job shouldn't have that. How did you edit your crontab? – muru Jul 1 '15 at 1:46
  • Thanks for fixing my code in the main question muru; sorry I did that wrong. I use nano for editing cron. Thank you for explaining that %U is for desktop files. I removed that from the line in cron and... it worked! 59 21 * * * DISPLAY=:0.0 steam in the user's cron (not root; that's bad I'm told) successfully started Steam! Thank you so much muru! (Can I mark your comment as the answer? I'm new to AskUbuntu!) – InverseTelecine Jul 1 '15 at 1:57
1
00 02 * * * DISPLAY=:0.0 steam

or (see edit below*)

00 02 * * * DISPLAY=:0.0 /usr/games/steam

(Thank you to muru for giving me the clue to figure this out!) This line in cron will start Steam every night at 02:00 (2:00AM).

The breakdown is this: the first part is standard cron "minutes, hours, days (of the month), months, days (of the week)", so the 00 means at zero minutes past the hour; the 02 means at 2 on the 12 hour clock (2:00AM); and having * in the locations for days, months, and days of the week means to do it on every day of every week of every month.

The DISPLAY=:0.0 I think has something to do with activating the graphical user interface at coordinates on the desktop, but I'm not sure. It's needed to make the line work; that's all I know for sure.

And steam is Steam.

If I figure out how to stop Steam from cron I will put it up, but I haven't figured that out yet. Thanks to everyone for their help!

*EDIT: Okay, so weeks later for some reason the original line I gave above: 00 02 * * * DISPLAY=:0.0 steam stopped working suddenly. I tried this slight alteration to the line and it works: 00 02 * * * DISPLAY=:0.0 /usr/games/steam I have no idea why but try them both and see which works for you.

For Linux noobs like me, you can find the full path like in the new line for any command by typing which [command] in the terminal; for example which steam shows /usr/games/steam which is what I used to make the line work again.

0

This might work:

cd ~/steamcmd
./steamcmd.sh

https://developer.valvesoftware.com/wiki/SteamCMD#Linux.2FOS_X

These are the commands to install updates:

Install or update the app using the app_update command (supplying a Steam Application ID). To also validate the app, add validate to the command. To download a beta branch, use the -beta option – for example, the HLDS beta branch is named beta and the SrcDS beta branch is named prerelease. Some beta branches are protected by a password; to be able to download from them, also add the -betapassword option.

2
  • Interesting! I'd never heard of SteamCMD. It doesn't look like SteamCMD is installed along with Steam by default, so I'd have to install it first before I could try that obviously. Seems a little extreme to have to install a whole new form of the client just to get it to run in a cron job, but it's possible that that is the only way I could set it up to do an unattended client update (assuming it would update the real Steam client and not just SteamCMD[??]). I'll have to look into it. I will report back. Thank you for the suggestion jnajna. – InverseTelecine Jul 1 '15 at 0:40
  • Just reading through that link it really doesn't look like SteamCMD would work for this. It doesn't sound like it's good for much more than running dedicated game servers. I don't need full command line control of the Steam client; I just want to launch the Steam client from cron, and if possible auto-update the client. Thank you anyway jnajna. – InverseTelecine Jul 1 '15 at 0:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.