#!/bin/bash # # Author: Wiebe Cazemier (wiebe@halfgaar.net) # # Template bash script, for when you need something overengineerd :) # Hack prevention PATH="/sbin:/usr/sbin:/bin:/usr/bin" # Error codes wrong_params=5 interrupted=99 default_error=1 # Function to echo in color. Don't supply color for normal color. echo_color() { message="$1" color="$2" red_begin="\033[01;31m" green_begin="\033[01;32m" yellow_begin="\033[01;33m" color_end="\033[00m" # Set color to normal when there is no color [ ! "$color" ] && color_begin="$color_end" if [ "$color" == "red" ]; then color_begin="$red_begin" fi if [ "$color" == "green" ]; then color_begin="$green_begin" fi if [ "$color" == "yellow" ]; then color_begin="$yellow_begin" fi echo -e "${color_begin}${message}${color_end}" } end() { message="$1" exit_status="$2" if [ -z "$exit_status" ]; then exit_status="0" fi if [ ! "$exit_status" -eq "0" ]; then echo_color "$message" "red" else echo_color "$message" "green" fi if [ "$exit_status" -eq "$wrong_params" ]; then dohelp fi exit $exit_status } # Define function to call when SIGTERM is received trap "end 'Interrupted' $interrupted" 1 2 3 15 dohelp() { echo "" echo "Example script" echo "" echo "help = todo" # Exit because you don't want the script to do anything after displaying help exit } while [ -n "$*" ]; do flag=$1 value=$2 case "$flag" in "--option1") option1=$value shift ;; "--help") dohelp ;; "--") break ;; *) end "unknown option $flag. Type --help" "$wrong_params" ;; esac shift done if [ -z "$option1" ]; then end "option1 not given" $wrong_params fi
Author: halfgaar (Page 12 of 26)
Halfgaar is Wiebe. Wiebe is a contributing author on this weblog. He also has a lot of stuff (such as long, in-depth articles) on his personal website.
Wiebe's day job is as a senior software developer and system administrator at YTEC.
In his free time, he built the free, open-source FlashMQ software. Together with Jeroen and Rowan, he is now building a managed MQTT hosting business around his open masterpiece.
Here is a code snippet I use for parameter parsing:
dohelp() { "Example script" "" # Exit because you don't want the script to do anything after # displaying help, and do so with error, so that calling scripts won't think it succeeded 1 } [ -n "$*" ]; flag="$1" value="$2" "$flag" "--one") one="$value" ;; "--two") two="$value" ;; "--pretend") pretend=true ;; "--help") dohelp ;; "--") ;; *) -e "unknown option $flag\n" dohelp ;;
On debian, to prevent:
Error: Could not stat() command file ‘/var/lib/nagios3/rw/nagios.cmd’!
Do:
/etc/init.d/nagios3 stop dpkg-statoverride --update --add nagios www-data 2710 /var/lib/nagios3/rw dpkg-statoverride --update --add nagios nagios 751 /var/lib/nagios3 /etc/init.d/nagios3 start
If you need services to be availble on multiple ports, you can use:
iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 1000 -j REDIRECT --to-port 25 --match comment --comment "Explain."
This makes port 1000 and 25 the same service.
source and source and source. I’m keeping it as simple as possible.
The serverside LAN in this example is 10.50.0.0/16.
On the server, install pptpd. Then edit /etc/pptpd.conf and set:
# This is the IP the server will have from the clients perspective. SHould be the servers local IP. localip 10.50.0.1 # And from this range, the client IPs will be given. Here, the range 10.50.91.x is reserved for VPN hosts. remoteip 10.50.91.1-254
Then edit /etc/ppp/pptpd-options and set options (comments have been removed from this example):
name my-pptpd
refuse-pap
refuse-chap
refuse-mschap
require-mschap-v2
require-mppe-128
proxyarp
nodefaultroute
lock
nobsdcomp
Then restart pptpd.
Then edit accounts in /etc/ppp/chap-secrets. Example:
user my-pptpd password *
On the client, /etc/options.pptp (comments once again removed):
lock noauth refuse-pap refuse-eap refuse-chap refuse-mschap nobsdcomp nodeflate
/etc/ppp/chap-secrets:
user my-pptpd password *
Then make /etc/ppp/peers/johnsvpn:
pty "pptp hostname --nolaunchpppd" name user remotename my-pptpd require-mppe-128 file /etc/ppp/options.pptp ipparam johnsvpn
You should then be able to turn it on with “pon johnsvpn”. Use poff to turn it off.
To be able to access the entire LAN from the client, run this:
route add -net 10.50.0.0 netmask 255.255.0.0 dev ppp0
More is necessary, like permanent host-to-LAN config (with route pushing or something), DNS, testing if windows works, etc. More is to come.
To boot a compaq Deskpro sff without keyboard, you need to configure the BIOS in a special way.
I found this:
– Run BIOS setup by pressing F10
– Goto ‘Security’ and ‘Set Power On Password’
– Type in a password and F10 to accept the change
– As soon as password is set, ‘Password Options’ will appear under ‘Security’ tab
– Enable ‘Network Server’ mode in there
– F10 to save changes and exitWhen booting up it won’t ask you for F1 anymore. However, if you or
someone else plugs in a keyboard it will ask for a power-on password.
Edit: This doesn’t work anymore I don’t think, because more modern versions check for SMTP conflicts and don’t allow this.
When you’re installing zimbra in an Ubuntu or Debian machine, it seems it installs the MTA in such a way that command line tools like mail and such don’t work. But when you install exim, it conflicts with the postfix in Zimbra.
To fix it, you can install exim4, but configure this line in /etc/default/exim4:
QUEUERUNNER='queueonly'
							
	There is a K01zimbra in rc6.d for reboot, but not in rc0.d. See this bug report I made.
Workaround:
cd /etc/rc0.d/ ln -s ../init.d/zimbra K01zimbra
I noticed that after an upgrade, the bootscript was gone again, so I made this cron task and put it in cron.daily:
#!/bin/bash # # Zimbra bug: no rc0 bootscript: http://bugzilla.zimbra.com/show_bug.cgi?id=54099 # # The bootscript I put there gets removed upon upgrade, so I put this script in # place which mails root if it is missing. # # The bug is fixed, but in 6.0.10 it still wasn't there, so I don't know when # it will be included in the release. # # Install it in /etc/cron.daily. ! [ -e "/etc/rc0.d/K01zimbra" -a -e "/etc/rc6.d/K01zimbra" ]; message="Kill zimbra bootscript not found in either rc0 (shutdown) or rc6 (reboot)." "$message" "$message" | mail -s "Zimbra bootscript error" root
Zimbra has a dependancy on ‘file’, which the installer file won’t check for. It is also a WONTFIX bug, so beware: install file(1)! If you don’t, mails get stuck in queue because amavisd won’t run.
A sort of bookmark: Dragonhide and absolute beginners guide.
Recent Comments