Shell Scripts

Create a server service

Create a server service thats run on the server startup

Bash script

Create a bash script (call it "myservice" or whatever) with 766 permisions, on server folder "/etc/init.d"

#!/bin/bash

case "$1" in
start)
  echo -n "[....] Starting service: myservice"
  # ...
  sleep 1 && echo -e "\e[0K\r[ \e[32mok\e[39m ]"
;;
stop)
  echo -n "[....] Stopping service: myservice"
  # ...
  sleep 1 && echo -e "\e[0K\r[ \e[32mok\e[39m ]"
;;
restart)
  echo -n "[....] Restarting service: myservice"
  # ...
  sleep 1 && echo -e "\e[0K\r[ \e[32mok\e[39m ]"
;;
*)
echo "Usage: /etc/init.d/myservice {start|stop|restart}"
exit 1
;;
esac
exit 0

Shell

Start or Stop the service from the shell

service myservice start
service myservice stop
service myservice restart

Compress files with gzip

Compress the Javascript and CSS files on the server for optimize web speed. It will be compressed into new files with a .gz extension. [ read ]

List files with options

List files on the current path on vertical display with invislible files, file permisions, owner and size in human readable format. [ read ]