ulfben icon

startup.service (exercise)

ulfben | PRO | 05/15/20 07:31:09 PM UTC | 0 ⭐ | 953 👁️ | Never ⏰ | []
Bash |

1.46 KB

|

None

|

0 👍

/

0 👎

###
### /etc/systemd/system/mystartupscript.service
###
[Unit]
Description=My Startup Script
Wants=network-online.target
After=network.target network-online.target
 
[Service]
Type=oneshot
ExecStart=/usr/local/bin/my_startup_script.sh
ExecStartPre=/bin/bash -c 'until host http://www.wttr.in; do sleep 1; done'
User=root
Group=root
 
[Install]
WantedBy=multi-user.target
 
 
###
### /usr/local/bin/my_startup_script.sh
###
#!/bin/bash
 
#error handler to exit with useful info
error() {
  local message="$1"
  local code="${2:-1}"
  echo "Error: ${message}; exiting with status ${code}" 1>&2
  exit "${code}"
}
 
#set up the variables - a directory to add to PATH, and a temporary output file
dirname='/opt/myapp/bin:'
outfile='/opt/myapp/weather.txt'
mkdir -p -- "$dirname" || error "Unable to create $dirname" 1;
touch "$outfile" || error "Failed to create $outfile" 1;
chmod 666 "$outfile"
 
#append directory to path
###avoiding spurious leading/trailing colon if $PATH is initially empty
###see https://unix.stackexchange.com/a/415028
##export PATH="${PATH:+${PATH}:}$dirname"
sed -e 's|'${dirname}'||g' -i /etc/environment
sed -e 's|PATH="\(.*\)"|PATH="'${dirname}'\1"|g' -i /etc/environment
 
#add timestamp to output file
date +%F:%T > "$outfile" || error "Unable to prepend timestamp to $outfile";
 
#append weather report to output file
curl -v 'http://wttr.in/Visby' >> "$outfile" || error "Unable to append weather report to $outfile";

Comments

  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎

    
        
  • Yuizcko icon
    05/18/26 01:00:47 PM UTC
    text |

    0 B

    |

    0 👍

    /

    0 👎

    Best t33n active cpx link daily updates!
     Copy and paste the link in a new browser tab and then hit enter!
     https://crazyporn.xxx/members/157354/?asgtbndr=1&play=true&spon=adworld&zone=400