shutdown script [SOLVED]

About writing shell scripts and making the most of your shell
Forum rules
Topics in this forum are automatically closed 6 months after creation.
Locked
cecilieaux
Level 5
Level 5
Posts: 742
Joined: Mon Dec 09, 2013 9:43 am
Location: Washington, D.C.

shutdown script [SOLVED]

Post by cecilieaux »

Trying to turn on the sync software for two cloud sites, so that new items get saved to the cloud before shutting down. I'm thinking something like

Code: Select all

#!/bin/bash
megasync
dropbox start -i
shutdown
Would that work? I'm very new at this. Please don't bash me (pun intended).
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 4 times in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
Cecilieaux
--
Every time I think I'm past newbiedom something like this happens.
Running Linux Mint 21 Vera with Cinnamon.
User avatar
Flemur
Level 20
Level 20
Posts: 10097
Joined: Mon Aug 20, 2012 9:41 pm
Location: Potemkin Village

Re: shutdown script

Post by Flemur »

cecilieaux wrote: Thu Feb 25, 2021 11:30 am Trying to turn on the sync software for two cloud sites, so that new items get saved to the cloud before shutting down. I'm thinking something like

Code: Select all

#!/bin/bash
megasync
dropbox start -i
shutdown
Would that work? I'm very new at this. Please don't bash me (pun intended).
I don't see why it wouldn't work (disclaimer: dunno anything about dropbox). I do something similar:
$ cat bin/Shutdown

Code: Select all

# mute audio and poweroff
amixer set 'Master',0        25%   mute
/bin/systemctl poweroff -i
This prevents the stereo from making an obnoxious popping noise when booting up.
Please edit your original post title to include [SOLVED] if/when it is solved!
Your data and OS are backed up....right?
cecilieaux
Level 5
Level 5
Posts: 742
Joined: Mon Dec 09, 2013 9:43 am
Location: Washington, D.C.

Re: shutdown script

Post by cecilieaux »

Flemur wrote: Thu Feb 25, 2021 11:43 am I don't see why it wouldn't work (disclaimer: dunno anything about dropbox).
I found out that there's a commandline version of megasync, megatools, which has specific parameters to do what I am proposing. Dropbox comes with a command line interface.
Cecilieaux
--
Every time I think I'm past newbiedom something like this happens.
Running Linux Mint 21 Vera with Cinnamon.
User avatar
Flemur
Level 20
Level 20
Posts: 10097
Joined: Mon Aug 20, 2012 9:41 pm
Location: Potemkin Village

Re: shutdown script

Post by Flemur »

cecilieaux wrote: Thu Feb 25, 2021 12:31 pm I found out that there's a commandline version of megasync, megatools, which has specific parameters to do what I am proposing. Dropbox comes with a command line interface.
My concern might be that they start something in background and it gets interrupted.
Please edit your original post title to include [SOLVED] if/when it is solved!
Your data and OS are backed up....right?
cecilieaux
Level 5
Level 5
Posts: 742
Joined: Mon Dec 09, 2013 9:43 am
Location: Washington, D.C.

Re: shutdown script

Post by cecilieaux »

Flemur wrote: Thu Feb 25, 2021 2:11 pm My concern might be that they start something in background and it gets interrupted.
Yes, that's my worry, too. Damn! I need a command for synching for each one. I need them to synch, then shut down.

This is no longer solved.
Cecilieaux
--
Every time I think I'm past newbiedom something like this happens.
Running Linux Mint 21 Vera with Cinnamon.
cecilieaux
Level 5
Level 5
Posts: 742
Joined: Mon Dec 09, 2013 9:43 am
Location: Washington, D.C.

Re: shutdown script

Post by cecilieaux »

Flemur wrote: Thu Feb 25, 2021 2:11 pm My concern might be that they start something in background and it gets interrupted.
OK, tried it. Megasync wouldn't turn off by itself and the shutdown hung until I clicked it shut. So, I did this:

Code: Select all

#!/bin/bash
megasync
dropbox start -i
time -300 -p
dropbox stop
killall -9 megasync
cinnamon-session-quit --power-off
Anyone see any red flags?
Cecilieaux
--
Every time I think I'm past newbiedom something like this happens.
Running Linux Mint 21 Vera with Cinnamon.
Welcome
Level 6
Level 6
Posts: 1026
Joined: Wed Aug 19, 2020 11:38 am

Re: shutdown script

Post by Welcome »

Instead of using the "time" command, did you mean to use the "sleep" command? Maybe something like "sleep 300" to wait for 5 minutes before shutting down?
ajgreeny
Level 7
Level 7
Posts: 1640
Joined: Mon Nov 19, 2007 3:27 pm

Re: shutdown script

Post by ajgreeny »

Could you use a single compound command rather than a script, separating each command you need to use with && which should mean each part runs only after the previous command has successfully completed.

In terminal try command

Code: Select all

bash -c "megasync && dropbox start -i && shutdown"
I have used such compound commands in my startup applications with success but never tried running one in terminal, but it should work as far as I can see.
User avatar
Termy
Level 12
Level 12
Posts: 4254
Joined: Mon Sep 04, 2017 8:49 pm
Location: UK
Contact:

Re: shutdown script

Post by Termy »

You're already using BASH in the terminal (presumably), and the syntax here isn't even BASH-specific, so there's no need to explicitly call for BASH in order to execute the commands you suggested.

Code: Select all

bash -c "megasync && dropbox start -i && shutdown"
In other words, the above is better executed as:

Code: Select all

megasync && dropbox start -i && shutdown
Do note that the system will not shut down if the dropbox command fails. && is the logical and operator (if the previous command is successful) and || is the logical or operator (if the previous command is unsuccessful), but ; is just interpreted as a new line, so whether the previous command fails or not, the command after ; will still execute.

The previous one-liner was the equivalent of getting into one car, immediately getting out, getting into a car parked right next to the first car, then driving off, when you could've just driven off in the first car.
I'm also Terminalforlife on GitHub.
Locked

Return to “Scripts & Bash”