Thursday, September 30, 2010
[AUR]chocolate-doom
I am the proud new maintainer of the chocolate-doom port. I updated the PKGBUILD and everything installed fine. I'll be mulling over the PKGBUILD script in the future to see what I can do to improve it.
Sunday, September 26, 2010
[update]chkroot
I rearranged the code to check for root then exit 0; if that fails, it checks for a quiet switch and echos an error message accordingly, then exit 1.
#!/bin/bash
if [[ $(id -u) = 0 ]]; then
exit 0
fi
[[ $1 = "-q" ]] || echo 'error: this script must be run with root privileges'
exit 1
if [[ $(id -u) = 0 ]]; then
exit 0
fi
[[ $1 = "-q" ]] || echo 'error: this script must be run with root privileges'
exit 1
Friday, September 24, 2010
chkroot
Since I have so many scripts that require root privileges to run, I wrote a simple script to do the check, so all I have to do is add a line in each script to run the check, rather than writing out the same if statement in every script.
Here's the check_root.sh script that I wrote:
and here's how it's called within other scripts:
Here's the check_root.sh script that I wrote:
#!/bin/bash
if [[ $(id -u) != 0 ]]; then
echo 'error: this script must be run with root privileges'
exit 1
fi
exit 0
if [[ $(id -u) != 0 ]]; then
echo 'error: this script must be run with root privileges'
exit 1
fi
exit 0
and here's how it's called within other scripts:
chkroot && [[ $? = 0 ]] || exit 1
[update]sysmon
I updated my sysmon script so that it actually works. I was having problems with the battery charge comparrison, I'm guess becuase of all the leading zeros. So, I put them in quotes and rather than using the actual greather-than, less-than ('>' '<') symbols, I used the '-gt/-lt' operators. Now, all is well in the system monitoring script.
#!/bin/zsh
# make sure user has root privileges
chkroot && [[ $? = 0 ]] || exit 1
log="/home/jason/devel/scripts/sysmon/sysmon.log"
ver=(0.0.3-1)
echo "" > $log
# define battery variables
charge_now='/sys/class/power_supply/BAT1/charge_now'
charge_full='/sys/class/power_supply/BAT1/charge_full'
charge_factor=20 # 5% battery power
# define temperature variables
max_temp=85
for i in {0..1}; do
temp_path="/sys/class/hwmon/hwmon$i/device/temp1_input"
[[ -f $temp_path ]] && break
done
# get full charge value
full="`cat $charge_full`"
# calculate the minimum charge based on the charge_factor
charge_min=$(($full/$charge_factor))
# just keep going
while [[ "1" = "1" ]]; do
# get current charge
charge="`cat $charge_now`"
# system doesn't use hwmon1 or hwmon0 exclusively, so there's a need to differentiate
temp="`cat $temp_path`"
temp=$temp[1,2]
#[[ $temp > $max_temp ]] || [[ $charge < $charge_min ]]
if [[ "$temp" -gt "$max_temp" ]]; then
echo `date` >> $log
echo "Shutdown due to high temp: $temp C" >> $log
shutdown -h now
fi
if [[ "$charge" -lt "$charge_min" ]]; then
echo `date` >> $log
echo "Shutdown due to low charge: $charge < $charge_min" >> $log
shutdown -h now
fi
sleep 10
done
# make sure user has root privileges
chkroot && [[ $? = 0 ]] || exit 1
log="/home/jason/devel/scripts/sysmon/sysmon.log"
ver=(0.0.3-1)
echo "" > $log
# define battery variables
charge_now='/sys/class/power_supply/BAT1/charge_now'
charge_full='/sys/class/power_supply/BAT1/charge_full'
charge_factor=20 # 5% battery power
# define temperature variables
max_temp=85
for i in {0..1}; do
temp_path="/sys/class/hwmon/hwmon$i/device/temp1_input"
[[ -f $temp_path ]] && break
done
# get full charge value
full="`cat $charge_full`"
# calculate the minimum charge based on the charge_factor
charge_min=$(($full/$charge_factor))
# just keep going
while [[ "1" = "1" ]]; do
# get current charge
charge="`cat $charge_now`"
# system doesn't use hwmon1 or hwmon0 exclusively, so there's a need to differentiate
temp="`cat $temp_path`"
temp=$temp[1,2]
#[[ $temp > $max_temp ]] || [[ $charge < $charge_min ]]
if [[ "$temp" -gt "$max_temp" ]]; then
echo `date` >> $log
echo "Shutdown due to high temp: $temp C" >> $log
shutdown -h now
fi
if [[ "$charge" -lt "$charge_min" ]]; then
echo `date` >> $log
echo "Shutdown due to low charge: $charge < $charge_min" >> $log
shutdown -h now
fi
sleep 10
done
Wednesday, September 22, 2010
Daily Activities
Follow-up on the shadow file. It just stores username, password, and date information pertaining to the password. From what I've read on the mailing list, the last changed date would set to sometime in the future, the update fixed this. Thus, the new file isn't really that important, I'll probably just have to update the root and other user dates. Anyway, here's a page explaining the file.
pactesting [update]
Looks like the resync isn't needed. Pacman will only sync and download the active repos in the config file. It doesn't remove the synced tarballs from the /var/lib/pacman directory. So, here's my updated script.
#!/bin/sh
config='/etc/pacman-testing.conf'
packages=""
# make sure the script is being run as root
if [[ $(id -u) != 0 ]]; then
echo "error: you must be root to run this script"
exit 1
fi
# Sync pacman with testing repos
pacman -Sy --config $config
# make sure packages exist
echo "checking package name(s)..."
for i in $@; do
pacman -Qi $i > /dev/null
[[ "$?" = "1" ]] && echo "skipping..." && continue
packages=$packages" $i"
done
if [[ $packages = "" ]]; then
echo "error: no existing packages received, resyncing repos and exiting..."
exit 1
fi
# upgrade packages
pacman -S --config $config $packages
exit 0
config='/etc/pacman-testing.conf'
packages=""
# make sure the script is being run as root
if [[ $(id -u) != 0 ]]; then
echo "error: you must be root to run this script"
exit 1
fi
# Sync pacman with testing repos
pacman -Sy --config $config
# make sure packages exist
echo "checking package name(s)..."
for i in $@; do
pacman -Qi $i > /dev/null
[[ "$?" = "1" ]] && echo "skipping..." && continue
packages=$packages" $i"
done
if [[ $packages = "" ]]; then
echo "error: no existing packages received, resyncing repos and exiting..."
exit 1
fi
# upgrade packages
pacman -S --config $config $packages
exit 0
Tuesday, September 21, 2010
Daily Activities
Just did an update of filesystem (2010.07-1 -> 2010.09-1) and it installed a new shadow file, /etc/shadow.pacnew. There are some noticable differences from the current /etc/shadow file. I will thus have to read up on the shadow file to figure out what everything is meant for and then reconcile the two.
I also noticed that when using the testing script I wrote, when resyncing the main repos, they'll be up to date. So, I'm not too sure if it is necesarry to resync these, or if just using switching back to the main configuration file is enough.
I also noticed that when using the testing script I wrote, when resyncing the main repos, they'll be up to date. So, I'm not too sure if it is necesarry to resync these, or if just using switching back to the main configuration file is enough.
Monday, September 20, 2010
pactesting -- script to install packages from the testing repos
Pretty simple script to install packages from the testing repos, the comments say it all. The pacman-testing.conf file is a copy of pacman.conf with only the [testing] and [community-testing] repos enabled.
#!/bin/sh
config='/etc/pacman-testing.conf'
packages=""
# make sure the script is being run as root
if [[ $(id -u) != 0 ]]; then
echo "error: you must be root to run this script"
exit 1
fi
# Sync pacman with testing repos
pacman -Sy --config $config
# make sure packages exist
echo "checking package name(s)..."
for i in $@; do
pacman -Qi $i > /dev/null
[[ "$?" = "1" ]] && echo "skipping..." && continue
packages=$packages" $i"
done
if [[ $packages = "" ]]; then
echo "error: no existing packages reveived, resyncing repos and exiting..."
pacman -Sy
exit 1
fi
# upgrade packages
pacman -S --config $config $packages
# resync with regular repos
pacman -Sy
exit 0
config='/etc/pacman-testing.conf'
packages=""
# make sure the script is being run as root
if [[ $(id -u) != 0 ]]; then
echo "error: you must be root to run this script"
exit 1
fi
# Sync pacman with testing repos
pacman -Sy --config $config
# make sure packages exist
echo "checking package name(s)..."
for i in $@; do
pacman -Qi $i > /dev/null
[[ "$?" = "1" ]] && echo "skipping..." && continue
packages=$packages" $i"
done
if [[ $packages = "" ]]; then
echo "error: no existing packages reveived, resyncing repos and exiting..."
pacman -Sy
exit 1
fi
# upgrade packages
pacman -S --config $config $packages
# resync with regular repos
pacman -Sy
exit 0
Friday, September 17, 2010
Daily Activities
Two things going on today, there are a couple vulnerabilities in the linux kerne, which can be found here. They have a proof of concept written in C, which works on the Archlinux kernel, an fix has been implemented, just waiting for it to hit the repos.
I'm also installing Arch on my thumbdrive, rather than just having the livecd on it, I can install other tools to it now. Anyhow, that's all.
I'm also installing Arch on my thumbdrive, rather than just having the livecd on it, I can install other tools to it now. Anyhow, that's all.
Tuesday, September 14, 2010
Daily Activities
Completed reading and taking notes on chapter 2 of the Zsh user guide. Now I need to go back and do related configurations to my system.
Monday, September 13, 2010
Wircon-0.0.2-1
I changed around the wireless-connection script. I created a status file, where the script would echo its status to (connected, disconnected, or down). I use this status on my conky bar. If the status is connected or disconnected, the script is running; if it's down, the script isn't. I also wrote in some traps do echo the 'down' status before the script exits. The last change is that it no longer exits after five attempts to connect, it keeps trying. Anyway, here it is:
#!/bin/sh
dhcpcdPID="/var/run/dhcpcd.pid"
networks=`cat /home/jason/devel/scripts/wircon/pref_networks.lst`
statfile="/home/jason/devel/scripts/wircon/status"
silent=1
# make sure the script is being run as root
if [[ $(id -u) != "0" ]]; then
echo "This script must be run as root"
exit 1
fi
# scan for essids located in pref_networks.lst
find_network() {
for i in $networks; do
iwlist wlan0 scan | grep $i &> /dev/null
if [[ "$?" = "0" ]]; then
local essid=$i
break
fi
done
case $essid in
"SouthPacific")
network="sp"
;;
"SouthPacific_Extender")
network="spx"
;;
"Belkin_G_Wireless_C973D1")
network="seans"
esac
}
# if dhcpcd is running, stop it
do_dhcpcd_check() {
if [[ -f $dhcpcdPID ]]; then
if [[ $silent = "1" ]]; then
dhcpcd -x
else
dhcpcd -x -q
fi
fi
}
# load wireless firmware
do_load_firmware() {
[[ $silent = "1" ]] && echo "loading wireless firmware"
ifconfig wlan0 up
}
# set essid and, if applicable, network key
do_set_network() {
[[ $silent = "1" ]] && echo "setting network parameters"
iwconfig wlan0 essid $ESSID
if [[ $KEY != "" ]]; then
iwconfig wlan0 key $KEY
fi
}
# unset the network for graceful exit
do_unset_network() {
do_dhcpcd_check
ifconfig wlan0 down
}
# try for dhcp lease
do_dhcpcd() {
if [[ $silent = "1" ]]; then
dhcpcd
else
dhcpcd -q
fi
}
# something that helps find a carrier
do_channel_auto() {
[[ $silent = "1" ]] && echo "connecting to carrier"
iwconfig wlan0 channel auto
}
# make sure it worked
check_connection() {
ping -c 1 www.google.com &> /dev/null
if [[ $? = "0" ]]; then
return 0
else
return 1
fi
}
# set the desired network
set_network() {
case $network in
"sp")
ESSID="SouthPacific"
KEY="6bcebdfbea3caf9f3cd36b31b8"
;;
"spx")
ESSID="SouthPacific_Extender"
KEY="6bcebdfbea3caf9f3cd36b31b8"
;;
"seans")
ESSID="Belkin_G_Wireless_C973D1"
KEY=
;;
*)
[[ $silent = "1" ]] && echo "$1 is not a recognized essid"
esac
}
connection_monitor() {
while [[ 1 = 1 ]]; do
sleep 10
check_connection
if [[ $? = 1 ]]; then
echo "disconnected" > $statfile
main
fi
echo "connected" > $statfile
done
}
# call all functions in proper order to establish connection
main() {
trap 'echo "down" > $statfile; do_unset_network; exit;' INT
trap 'echo "down" > $statfile; do_unset_network; exit;' TERM
while [[ 1 = 1 ]]; do
do_dhcpcd_check
do_load_firmware
do_set_network
sleep 2
do_dhcpcd
do_channel_auto
check_connection
if [[ $? = 0 ]]; then
[[ $silent = "1" ]] && echo "connection established"
connection_monitor
fi
done
}
# check scripts usage
if [[ $# > 0 ]]; then
if [[ $1 = "-s" ]]; then
silent=0
shift
fi
if [[ ! -z $1 ]]; then
network=$1
else
do_load_firmware
find_network
fi
else
do_load_firmware
find_network
fi
set_network
main
exit 2
dhcpcdPID="/var/run/dhcpcd.pid"
networks=`cat /home/jason/devel/scripts/wircon/pref_networks.lst`
statfile="/home/jason/devel/scripts/wircon/status"
silent=1
# make sure the script is being run as root
if [[ $(id -u) != "0" ]]; then
echo "This script must be run as root"
exit 1
fi
# scan for essids located in pref_networks.lst
find_network() {
for i in $networks; do
iwlist wlan0 scan | grep $i &> /dev/null
if [[ "$?" = "0" ]]; then
local essid=$i
break
fi
done
case $essid in
"SouthPacific")
network="sp"
;;
"SouthPacific_Extender")
network="spx"
;;
"Belkin_G_Wireless_C973D1")
network="seans"
esac
}
# if dhcpcd is running, stop it
do_dhcpcd_check() {
if [[ -f $dhcpcdPID ]]; then
if [[ $silent = "1" ]]; then
dhcpcd -x
else
dhcpcd -x -q
fi
fi
}
# load wireless firmware
do_load_firmware() {
[[ $silent = "1" ]] && echo "loading wireless firmware"
ifconfig wlan0 up
}
# set essid and, if applicable, network key
do_set_network() {
[[ $silent = "1" ]] && echo "setting network parameters"
iwconfig wlan0 essid $ESSID
if [[ $KEY != "" ]]; then
iwconfig wlan0 key $KEY
fi
}
# unset the network for graceful exit
do_unset_network() {
do_dhcpcd_check
ifconfig wlan0 down
}
# try for dhcp lease
do_dhcpcd() {
if [[ $silent = "1" ]]; then
dhcpcd
else
dhcpcd -q
fi
}
# something that helps find a carrier
do_channel_auto() {
[[ $silent = "1" ]] && echo "connecting to carrier"
iwconfig wlan0 channel auto
}
# make sure it worked
check_connection() {
ping -c 1 www.google.com &> /dev/null
if [[ $? = "0" ]]; then
return 0
else
return 1
fi
}
# set the desired network
set_network() {
case $network in
"sp")
ESSID="SouthPacific"
KEY="6bcebdfbea3caf9f3cd36b31b8"
;;
"spx")
ESSID="SouthPacific_Extender"
KEY="6bcebdfbea3caf9f3cd36b31b8"
;;
"seans")
ESSID="Belkin_G_Wireless_C973D1"
KEY=
;;
*)
[[ $silent = "1" ]] && echo "$1 is not a recognized essid"
esac
}
connection_monitor() {
while [[ 1 = 1 ]]; do
sleep 10
check_connection
if [[ $? = 1 ]]; then
echo "disconnected" > $statfile
main
fi
echo "connected" > $statfile
done
}
# call all functions in proper order to establish connection
main() {
trap 'echo "down" > $statfile; do_unset_network; exit;' INT
trap 'echo "down" > $statfile; do_unset_network; exit;' TERM
while [[ 1 = 1 ]]; do
do_dhcpcd_check
do_load_firmware
do_set_network
sleep 2
do_dhcpcd
do_channel_auto
check_connection
if [[ $? = 0 ]]; then
[[ $silent = "1" ]] && echo "connection established"
connection_monitor
fi
done
}
# check scripts usage
if [[ $# > 0 ]]; then
if [[ $1 = "-s" ]]; then
silent=0
shift
fi
if [[ ! -z $1 ]]; then
network=$1
else
do_load_firmware
find_network
fi
else
do_load_firmware
find_network
fi
set_network
main
exit 2
Testing VMs
I created two Archlinux virtual machines, one for i686 and one for x86_64. I have the testing repos enabled on both so I can test the packages. While I can't signoff on packages, I can report bugs in the signoff threads. Apparently this is something that not many people do, so it's a start.
Friday, September 10, 2010
Daily Activities
I remembered this morning that I had done an lsorphans, by mistake actually, and it yielded several results. So, I did an rmorphans. One of the packages removed was HAL. It appears that nothing on my system relies on HAL anylonger. However, VMware does. So, I had to reinstall HAL with the --asexplicit switch, so that it wouldn't appear in an orphan listing anymore.
Thursday, September 9, 2010
wircon-0.0.1-1 -- a wireless detection/connection script for broadcom 43** wireless cards
I wrote this because none of the available programs seem to handle the Broadcom 43** wireless cards very well. The script has a couple of options. It can be sent a pre-determined network nickname to connect to, or it can read from a list of "preferred networks" and connect to whichever it finds first. It also contains a silent (-s) switch, which removes all output. The network nickname is what's passed to the script when called, so with wircon home, once the script reached the "set_network" function, it would set the ESSID corresponding to 'home'. This way one doesn't have to type out 'FooBar_G_Serial_0834DS90' everytime they want to connect to that network. However, the preferred networks file 'pref_networks.lst' should contain the actual network ESSID.
The script has been completely modularized, so it's run as a series of functions. It's also meant to be backgrounded as it will switch to a function which loops infinitely, checking the internet connection with each iteration; if none is found, it calls the main connection cycle again and repeats. If it is unable to connect after 5 tries, it exits completely with an errorcode of 1.
The script has been completely modularized, so it's run as a series of functions. It's also meant to be backgrounded as it will switch to a function which loops infinitely, checking the internet connection with each iteration; if none is found, it calls the main connection cycle again and repeats. If it is unable to connect after 5 tries, it exits completely with an errorcode of 1.
#!/bin/sh
dhcpcdPID="/var/run/dhcpcd.pid"
networks=`cat /home/jason/devel/scripts/wircon/pref_networks.lst`
# make sure the script is being run as root
if [[ $(id -u) != "0" ]]; then
echo "This script must be run as root"
exit 1
fi
# scan for essids located in pref_networks.lst
find_network() {
for i in $networks; do
iwlist wlan0 scan | grep $i &> /dev/null
if [[ "$?" = "0" ]]; then
local essid=$i
break
fi
done
case $essid in
"[Network_ESSID1")
network="NE1"
;;
"[Network_ESSID2")
network="NE2"
;;
"Network_ESSID3")
network="NE3"
esac
}
# if dhcpcd is running, stop it
do_dhcpcd_check() {
if [[ -f $dhcpcdPID ]]; then
if [[ $silent = "1" ]]; then
dhcpcd -x
else
dhcpcd -x -q
fi
fi
}
# load wireless firmware
do_load_firmware() {
[[ $silent = "1" ]] && echo "loading wireless firmware"
ifconfig wlan0 up
}
# set essid and, if applicable, network key
do_set_network() {
[[ $silent = "1" ]] && echo "setting network parameters"
iwconfig wlan0 essid $ESSID
if [[ $KEY != "" ]]; then
iwconfig wlan0 key $KEY
fi
}
# try for dhcp lease
do_dhcpcd() {
if [[ $silent = "1" ]]; then
dhcpcd
else
dhcpcd -q
fi
}
# something that helps find a carrier
do_channel_auto() {
[[ $silent = "1" ]] && echo "connecting to carrier"
iwconfig wlan0 channel auto
}
# make sure it worked
check_connection() {
ping -c 1 www.google.com &> /dev/null
if [[ $? = "0" ]]; then
return 0
else
return 1
fi
}
# set the desired network
set_network() {
case $network in
"NE1")
ESSID="[Network_ESSID1]"
KEY="biglongkey"
;;
"NE2")
ESSID="[Network_ESSID2]"
KEY="hopefullydifferentbiglongkey"
;;
"NE3")
ESSID="[Network_ESSID3]"
# unsecure network
KEY=
;;
*)
[[ $silent = "1" ]] && echo "$1 is not a recognized essid"
esac
}
connection_monitor() {
while [[ 1 = 1 ]]; do
sleep 10
check_connection
if [[ $? = 1 ]]; then
main
fi
done
}
main() {
count=0
while [[ $count < 5 ]]; do
do_dhcpcd_check
do_load_firmware
do_set_network
sleep 2
do_dhcpcd
do_channel_auto
check_connection
if [[ $? = 0 ]]; then
[[ $silent = "1" ]] && echo "connection established"
connection_monitor
else
let count=$count+1
fi
done
}
# check scripts usage
silent=1
if [[ $# > 0 ]]; then
if [[ $1 = "-s" ]]; then
silent=0
shift
fi
if [[ ! -z $1 ]]; then
network=$1
else
find_network
fi
else
find_network
fi
set_network
main
exit 1
dhcpcdPID="/var/run/dhcpcd.pid"
networks=`cat /home/jason/devel/scripts/wircon/pref_networks.lst`
# make sure the script is being run as root
if [[ $(id -u) != "0" ]]; then
echo "This script must be run as root"
exit 1
fi
# scan for essids located in pref_networks.lst
find_network() {
for i in $networks; do
iwlist wlan0 scan | grep $i &> /dev/null
if [[ "$?" = "0" ]]; then
local essid=$i
break
fi
done
case $essid in
"[Network_ESSID1")
network="NE1"
;;
"[Network_ESSID2")
network="NE2"
;;
"Network_ESSID3")
network="NE3"
esac
}
# if dhcpcd is running, stop it
do_dhcpcd_check() {
if [[ -f $dhcpcdPID ]]; then
if [[ $silent = "1" ]]; then
dhcpcd -x
else
dhcpcd -x -q
fi
fi
}
# load wireless firmware
do_load_firmware() {
[[ $silent = "1" ]] && echo "loading wireless firmware"
ifconfig wlan0 up
}
# set essid and, if applicable, network key
do_set_network() {
[[ $silent = "1" ]] && echo "setting network parameters"
iwconfig wlan0 essid $ESSID
if [[ $KEY != "" ]]; then
iwconfig wlan0 key $KEY
fi
}
# try for dhcp lease
do_dhcpcd() {
if [[ $silent = "1" ]]; then
dhcpcd
else
dhcpcd -q
fi
}
# something that helps find a carrier
do_channel_auto() {
[[ $silent = "1" ]] && echo "connecting to carrier"
iwconfig wlan0 channel auto
}
# make sure it worked
check_connection() {
ping -c 1 www.google.com &> /dev/null
if [[ $? = "0" ]]; then
return 0
else
return 1
fi
}
# set the desired network
set_network() {
case $network in
"NE1")
ESSID="[Network_ESSID1]"
KEY="biglongkey"
;;
"NE2")
ESSID="[Network_ESSID2]"
KEY="hopefullydifferentbiglongkey"
;;
"NE3")
ESSID="[Network_ESSID3]"
# unsecure network
KEY=
;;
*)
[[ $silent = "1" ]] && echo "$1 is not a recognized essid"
esac
}
connection_monitor() {
while [[ 1 = 1 ]]; do
sleep 10
check_connection
if [[ $? = 1 ]]; then
main
fi
done
}
main() {
count=0
while [[ $count < 5 ]]; do
do_dhcpcd_check
do_load_firmware
do_set_network
sleep 2
do_dhcpcd
do_channel_auto
check_connection
if [[ $? = 0 ]]; then
[[ $silent = "1" ]] && echo "connection established"
connection_monitor
else
let count=$count+1
fi
done
}
# check scripts usage
silent=1
if [[ $# > 0 ]]; then
if [[ $1 = "-s" ]]; then
silent=0
shift
fi
if [[ ! -z $1 ]]; then
network=$1
else
find_network
fi
else
find_network
fi
set_network
main
exit 1
Tuesday, September 7, 2010
[update]sysmon-0.0.2-3
I had to make a couple changes. I accidentally had the battery charge check against the full value, so any time I unplugged my laptop, it would shutdown. Also, while it appeared to work correctly, I forgot that the value of temp1_input was in thousands. Thus, a temperature of 53C would be 53000. So, I removed the zeros.
#!/bin/zsh
# define battery variables
charge_now='/sys/class/power_supply/BAT1/charge_now'
charge_full='/sys/class/power_supply/BAT1/charge_full'
charge_factor=20 # 5% battery power
# define temperature variables
max_temp=80
for i in {0..1}; do
temp_path="/sys/class/hwmon/hwmon$i/device/temp1_input"
[[ -f $temp_path ]] && break
done
# get full charge value
full="`cat $charge_full`"
# just keep going
while [[ "1" = "1" ]]; do
# get current charge
charge="`cat $charge_now`"
# calculate the minimum charge based on the charge_factor
charge_min=$(($full/$charge_factor))
# system doesn't use hwmon1 or hwmon0 exclusively, so there's a need to differentiate
temp="`cat $temp_path`"
temp=$temp[1,2]
[[ $temp > $max_temp ]] || [[ $charge < $charge_min ]] && `shutdown -h now` sleep 10 done
# define battery variables
charge_now='/sys/class/power_supply/BAT1/charge_now'
charge_full='/sys/class/power_supply/BAT1/charge_full'
charge_factor=20 # 5% battery power
# define temperature variables
max_temp=80
for i in {0..1}; do
temp_path="/sys/class/hwmon/hwmon$i/device/temp1_input"
[[ -f $temp_path ]] && break
done
# get full charge value
full="`cat $charge_full`"
# just keep going
while [[ "1" = "1" ]]; do
# get current charge
charge="`cat $charge_now`"
# calculate the minimum charge based on the charge_factor
charge_min=$(($full/$charge_factor))
# system doesn't use hwmon1 or hwmon0 exclusively, so there's a need to differentiate
temp="`cat $temp_path`"
temp=$temp[1,2]
[[ $temp > $max_temp ]] || [[ $charge < $charge_min ]] && `shutdown -h now` sleep 10 done
System Backup
I need to start backing up my system. I was just reading about a guy who lost everything on his machine to an unclean reboot. For the future, once I get my server going again, I would like to create a networked sync with it.
Monday, September 6, 2010
[complete]sysmon-0.0.2-2
Finished it all. I accidentally left an echo in the previous release. So, here's the completed script.
And here's the init script that I wrote up for it.
#!/bin/zsh
# define battery variables
charge_now='/sys/class/power_supply/BAT1/charge_now'
charge_full='/sys/class/power_supply/BAT1/charge_full'
charge_factor=20 # 5% battery power
# define temperature variables
max_temp=80
for i in {0..1}; do
temp_path="/sys/class/hwmon/hwmon$i/device/temp1_input"
[[ -f $temp_path ]] && break
done
# get full charge value
full="`cat $charge_full`"
# just keep going
while [[ "1" = "1" ]]; do
# get current charge
charge="`cat $charge_now`"
# calculate the minimum charge based on the charge_factor
charge_min=$(($full/$charge_factor))
# system doesn't use hwmon1 or hwmon0 exclusively, so there's a need to differentiate
temp="`cat $temp_path`"
[[ $temp > $max_temp ]] || [[ $charge < $full ]] && `shutdown -h now` sleep 10 done
# define battery variables
charge_now='/sys/class/power_supply/BAT1/charge_now'
charge_full='/sys/class/power_supply/BAT1/charge_full'
charge_factor=20 # 5% battery power
# define temperature variables
max_temp=80
for i in {0..1}; do
temp_path="/sys/class/hwmon/hwmon$i/device/temp1_input"
[[ -f $temp_path ]] && break
done
# get full charge value
full="`cat $charge_full`"
# just keep going
while [[ "1" = "1" ]]; do
# get current charge
charge="`cat $charge_now`"
# calculate the minimum charge based on the charge_factor
charge_min=$(($full/$charge_factor))
# system doesn't use hwmon1 or hwmon0 exclusively, so there's a need to differentiate
temp="`cat $temp_path`"
[[ $temp > $max_temp ]] || [[ $charge < $full ]] && `shutdown -h now` sleep 10 done
And here's the init script that I wrote up for it.
#!/bin/sh
. /etc/rc.d/functions
PID="`pidof -x sysmond 2>/dev/null`"
case "$1" in
start)
stat_busy "Starting System Monitor"
/usr/bin/sysmond &
if [[ $? -gt 0 ]]; then
stat_fail
else
stat_done
fi
;;
stop)
stat_busy "Stopping System Monitor"
[[ ! -z $PID ]] && kill $PID
if [[ "$?" = "0" ]]; then
stat_done
else
stat_fail
fi
;;
restart)
$0 stop
sleep 1
$0 start
;;
*)
echo "ussage: $0 {start|stop|restart}"
esac
exit 0
. /etc/rc.d/functions
PID="`pidof -x sysmond 2>/dev/null`"
case "$1" in
start)
stat_busy "Starting System Monitor"
/usr/bin/sysmond &
if [[ $? -gt 0 ]]; then
stat_fail
else
stat_done
fi
;;
stop)
stat_busy "Stopping System Monitor"
[[ ! -z $PID ]] && kill $PID
if [[ "$?" = "0" ]]; then
stat_done
else
stat_fail
fi
;;
restart)
$0 stop
sleep 1
$0 start
;;
*)
echo "ussage: $0 {start|stop|restart}"
esac
exit 0
[tested]sysmon-0.0.2-1
Here it is, all updated and tested. Turned out I had a couple mismatched variables, but the logic works like a charm. Next will be to implement it in an init script for the boot procedure.
#!/bin/zsh
# define battery variables
charge_now='/sys/class/power_supply/BAT1/charge_now'
charge_full='/sys/class/power_supply/BAT1/charge_full'
charge_factor=20 # 5% battery power
# define temperature variables
max_temp=80
for i in {0..1}; do
temp_path="/sys/class/hwmon/hwmon$i/device/temp1_input"
[[ -f $temp_path ]] && break
done
# get full charge value
full="`cat $charge_full`"
# just keep going
while [[ "1" = "1" ]]; do
# get current charge
charge="`cat $charge_now`"
# calculate the minimum charge based on the charge_factor
charge_min=$(($full/$charge_factor))
echo "min charge: $charge_min"
# system doesn't use hwmon1 or hwmon0 exclusively, so there's a need to differentiate
temp="`cat $temp_path`"
[[ $temp > $max_temp ]] || [[ $charge < $full ]] && `shutdown -h now` sleep 10 done
# define battery variables
charge_now='/sys/class/power_supply/BAT1/charge_now'
charge_full='/sys/class/power_supply/BAT1/charge_full'
charge_factor=20 # 5% battery power
# define temperature variables
max_temp=80
for i in {0..1}; do
temp_path="/sys/class/hwmon/hwmon$i/device/temp1_input"
[[ -f $temp_path ]] && break
done
# get full charge value
full="`cat $charge_full`"
# just keep going
while [[ "1" = "1" ]]; do
# get current charge
charge="`cat $charge_now`"
# calculate the minimum charge based on the charge_factor
charge_min=$(($full/$charge_factor))
echo "min charge: $charge_min"
# system doesn't use hwmon1 or hwmon0 exclusively, so there's a need to differentiate
temp="`cat $temp_path`"
[[ $temp > $max_temp ]] || [[ $charge < $full ]] && `shutdown -h now` sleep 10 done
sysmon0.0.1-4 -- Monitor cpu temp and battery charge for unacceptable levels
I wrote this script with intent to background. If the battery charge gets below 5% or the cpu temperature climbs above 80C, the command to halt is issued.
This is a running version. I have not tested to see if it will execute properly once the conditions are met. Setting it to short term list, most likely tomorrow.
#!/bin/zsh
# define battery variables
charge_now='/sys/class/power_supply/BAT1/charge_now'
charge_full='/sys/class/power_supply/BAT1/charge_full'
charge_factor=20 # 5% battery power
# define temperature variables
max_temp=80
for i in {0..1}; do
temp_path="/sys/class/hwmon/hwmon$i/device/temp1_input"
[[ -f $temp_path ]] && break
done
# get full charge value
full=`cat $charge_full`
# just keep going
while [[ "1" = "1" ]]; do
# get current charge
charge=`cat $charge_now`
# calculate the minimum charge based on the charge_factor
charge_min=$(($full/$charge_factor))
# system doesn't use hwmon1 or hwmon0 exclusively, so there's a need to differentiate
temp="`cat $temp_path`"
[[ "$?" = "0" ]] || continue
[[ $temp > 80 ]] || [[ $charge < $min_charge ]] && `shutdown -h now` sleep 10 done
# define battery variables
charge_now='/sys/class/power_supply/BAT1/charge_now'
charge_full='/sys/class/power_supply/BAT1/charge_full'
charge_factor=20 # 5% battery power
# define temperature variables
max_temp=80
for i in {0..1}; do
temp_path="/sys/class/hwmon/hwmon$i/device/temp1_input"
[[ -f $temp_path ]] && break
done
# get full charge value
full=`cat $charge_full`
# just keep going
while [[ "1" = "1" ]]; do
# get current charge
charge=`cat $charge_now`
# calculate the minimum charge based on the charge_factor
charge_min=$(($full/$charge_factor))
# system doesn't use hwmon1 or hwmon0 exclusively, so there's a need to differentiate
temp="`cat $temp_path`"
[[ "$?" = "0" ]] || continue
[[ $temp > 80 ]] || [[ $charge < $min_charge ]] && `shutdown -h now` sleep 10 done
This is a running version. I have not tested to see if it will execute properly once the conditions are met. Setting it to short term list, most likely tomorrow.
[solved]Virtual Machine Crashes on Start in VMware Player
Turns out I didn't have to reinstall vmplayer. I simply had to rebuild the modules. I figured it had something to do with the recent kernel upgrade, although I figured the kernel26-2.6.35.4-1 release had broken vmplayer. It does make sense, however, that the kernel modules needed to be rebuilt. Atleast, now I know to rebuild such packages upon kernel updates.
vmware-modconfig --console --install-all
New Post Methodology
Instead of just posting 'Daily Activities' every day, I'm going to place any issues within their own post. The title of the post will be a concise description of its contents i.e. foobar-0.0.1-1 crashes on start. This way problems and projects can be searched and followed more efficiently. There will also potentially be a 'Daily Activities' section. This will include the miscilaneous things that might not completely deserve their own topic.
Sunday, September 5, 2010
Daily Activities
03:10AM ::
Now next-morning. I forgot there was a pacman update today. Fixed the rankmirrors problem. There were also updates to sudo, vim, and chromium. All is well for now.
10:15PM ::
Wrote up a script to be backgrounded that will check the battery charge and cpu temp. and halt the system if either is out of an acceptable range. I still have test and impliment it.
VMware Player is not starting up the WinXP VM that I created, so I'll have to look into that. I'm guess that a recent update might of broken something and I'll have to re-install.
More later...
Now next-morning. I forgot there was a pacman update today. Fixed the rankmirrors problem. There were also updates to sudo, vim, and chromium. All is well for now.
10:15PM ::
Wrote up a script to be backgrounded that will check the battery charge and cpu temp. and halt the system if either is out of an acceptable range. I still have test and impliment it.
VMware Player is not starting up the WinXP VM that I created, so I'll have to look into that. I'm guess that a recent update might of broken something and I'll have to re-install.
More later...
Friday, September 3, 2010
Daily Activities
5:00PM ::
I actually did this yesterday. I added a feature to my conky bar, it shows how many updates are available for my system. I put a script in cron.hourly which just runs `pacman -Sy` to update the local database. Then conky calls a script every 60 minutes that runs `pacman -Qu -b /var/lib/pacman` (/var/lib/pacman contains to local pacman databases), then returns the number of packages available.
I thought I read something about being able to put all of your small scripts into one fo the zsh files rather than creating a bunch of files. So, I'm looking into doing this as well.
I've also thought about implementing failsafes for my battery charge and cpu temperature. If they get too low and/or too high respectively, I'll have the computer shut itself down.
I also had another thought to do something last night, but completely forgot what it was. Hopefully I'll remember sometime soon. Until then, that's all for now.
I actually did this yesterday. I added a feature to my conky bar, it shows how many updates are available for my system. I put a script in cron.hourly which just runs `pacman -Sy` to update the local database. Then conky calls a script every 60 minutes that runs `pacman -Qu -b /var/lib/pacman` (/var/lib/pacman contains to local pacman databases), then returns the number of packages available.
I thought I read something about being able to put all of your small scripts into one fo the zsh files rather than creating a bunch of files. So, I'm looking into doing this as well.
I've also thought about implementing failsafes for my battery charge and cpu temperature. If they get too low and/or too high respectively, I'll have the computer shut itself down.
I also had another thought to do something last night, but completely forgot what it was. Hopefully I'll remember sometime soon. Until then, that's all for now.
Subscribe to:
Posts (Atom)