Custom Search

Sunday, November 08, 2009

Conky Update

Added some information at the end of Conky System Statistics
on a new way to stop one version of Conky from a script that runs
from a cronjob and start a new version, again from a script run
from a cronjob. Hope if anyone used the old way they didn't have
the same problem I did. If so, sorry. The current way has been
working without issue for several days now.

Cheers!

Labels: , , ,

Sunday, November 01, 2009

Tweeting From the Command Line

Recently ran across an article Tweeting from the command line,
so I thought I’d give it a try. Didn’t have a Twitter account,
so that was the first step, creating one. Go to Twitter and
create your account.
After that, you need to copy the script and put in your username
and password and make the script executable. I placed my script
in ~/bin and did a chmod 700 ~/bin/tweet.sh so the script
is only executable, readable, and writable by me. Here’s the script:

#!/bin/sh

tweet="${@}"

user="username"

pass="sekret"

if  [ $(echo  "${tweet}" | wc -c) -gt 140 ];  then

     echo "FATAL: The tweet is longer than 140 characters!"

     exit 1

fi

curl -k -u ${user}:${pass} -d status="${tweet}"
https://twitter.com/statuses/update.xml >/dev/null 2>&1
if [ "$?" == "0" ]; then

echo "Successful tweet!"

fi

The full instructions are at the link listed above at
the beginning of this blog entry. It mentions escaping
special characters such as "?" and "!" for one thing,
and that’s important. I read the other night where you
can’t edit a "Tweet", only delete it, going on to explain
that anyone following you would not be in sync with your
Tweets if you deleted an entry and then entered a new
version of it. I erroneously thought, also, that to Retweet
meant doing a Tweet over, but it's actually more like
passing on what someone else has already Tweeted.
Obviously I've still got a lot to learn about Twitter, but
the script above should get my fellow CLI geeks going. ;)

Cheers!

Addendum:
TTYtter for Perl: More Tweeting from the command line


TTYtter: an interactive console text-based command-line Twitter client and Perl platform

Just a follow up on Tweeting from the command line.
Cool setup. ANSI Graphics, too. Check it out.


Cheers!

Labels: , , , , , ,

Saturday, October 31, 2009

Tracking Network Usage With a Shell Script

Every morning the daily output is waiting there for
me in my email. Part of the normal output under Ipkts
and Opkts shows what went through the interface:

Ipkts            Opkts
2999812      2509494

I don’t reboot very often but when I do, it seems the system
zeros this out and it starts all over again. I put together
a script that runs periodically from a cronjob:

#!/bin/sh
# Filename: netusage.sh

cd $HOME/bin
if grep ‘daily output’ $HOME/Mail/root/new/*; then
cat `grep -l ‘daily output’ ~/Mail/root/new/*` | \
grep xl0 |tail -1 |awk ‘{print $5}’ > ibytes.out
cat `grep -l ‘daily output’ ~/Mail/root/new/*` | \
grep xl0 |tail -1 |awk ‘{print $7}’ > obytes.out

else
echo “No daily output yet” > /dev/null 2>&1
fi
cd

At the end of the month I run another script to total
the network usage:

#!/bin/sh
# Filename: netusemonthly.sh
cd $HOME/bin
date > `date +”%Y%m%d”`_endofmonthnetuse.log
echo “” >> `date +”%Y%m%d”`_endofmonthnetuse.log
echo “Monthly Ibytes” >> `date +”%Y%m%d”`_endofmonthnetuse.log
cat *ibytes.out |awk ‘{ SUM += $1 } END { print SUM }’ >> \
`date +”%Y%m%d”`_endofmonthnetuse.log
echo “” >> `date +”%Y%m%d”`_endofmonthnetuse.log
echo “Monthly Obytes” >> \
`date +”%Y%m%d”`_endofmonthnetuse.log
cat *obytes.out |awk ‘{ SUM += $1 } END { print SUM }’ >> \
`date +”%Y%m%d”`_endofmonthnetuse.log
mv -f *ibytes.out *obytes.out rebytes/
mv -f *endofmonthnetuse.log rebytes/
cd

The file names I used probably look ludicrous and they are all
completely arbitrary. If you try this out you can use whatever
file names and paths suit your needs. The whole thing was done
just to learn more about scripting, awk, and so forth. Also, to keep
the numbers right after a reboot, I added the following to
/etc/rc.shutdown:

netstat -ivn |head -8 |tail -1 |awk ‘{print $5}’ > \
/home/useracct/bin/`date +”%Y%m%d%H:%M:%S”`_reboot_ibytes.out
netstat -ivn |head -8 |tail -1 |awk ‘{print $7}’ > \
/home/useracct/bin/`date +”%Y%m%d%H:%M:%S”`_reboot_obytes.out
chown useracct:useracct /home/useracct/bin/*reboot_*bytes*

Like I said, this was all done just for learning purposes.
Maybe you can find a way to use some variation of the idea
on your own system.

Cheers!

Labels: , , , ,

Saving Tips From Mailing Lists

Besides my constant experimentation towards always
learning more about OpenBSD, one of my other means
of accumulating tips is from the mailing lists I
subscribe to. I put together a script to save messages
from the misc@openbsd mailing list. It finds all the
messages in thread in my mutt subdirectory under Mail
and concatenates all of them to a text file. It’s
interactive and it asks you for a search pattern,
where to search, and where to save the output to.
Here’s what it looks like:

#!/bin/sh
# Filename: obsd2tips.sh – save mailing list problem
# questions and resolutions to my BSD tips folder

echo “Enter your search pattern: ”
read r

echo “Enter your search path: ”
read R

echo “Enter file to save to: ”
read i

cat `grep -l “$r” $HOME/$R/*` | \
sed ‘/Return-Path/,/X-Virus-Checker-Version/d’ >> \
$HOME/bsd/$i.txt

The stuff like Return-Path and X-Virus-Checker-Version
are stuff in my header I don’t want in the saved tip.
If it was just a single message I could strip the entire
header with a sed command, but it doesn’t work when there
is more than one message in the thread. It gets even more
complicated on the script I use to do the same thing with
my freebsd-questions mailing list threads. Here’s that
script and you will see the difference:

#!/bin/sh
# Filename: fbsd2tips.sh – save mailing list problem
# questions and resolutions to my BSD tips folder

echo “Enter your search pattern: ”
read r

echo “Enter your search path: ”
read R

echo “Enter file to save to: ”
read i

cat `grep -l “$r” $HOME/$R/*` | \
sed ‘/Return-Path/,/X-Virus-Checker-Version/d’ | \
sed ‘/freebsd-questions/d’ |sed ‘/unsubscribe/d’ >> \
$HOME/bsd/$i.txt

Depending on your MUA you will have to adjust your
filtering. I’ve been using mutt for years and do not
have any intention of switching to anything else. So,
if you’re using mutt, it will be easy to implement
for you. If you’re using some other MUA YMMV. ;)

Cheers!

Sat Oct 31 14:35:33 CDT 2009
Addendum:

Made the script a bit more interactive and helpful.
Thanks go to my friend Girish for helping me on it,
too. Here’s the new script for searching through my
misc@openbsd mail threads:

#!/bin/sh
# Filename: obsd2tips.sh – save mailing list problem
# resolutions to my BSD tips folder
found=”N”
while [ "$found" = "N" ]; do
echo “Enter your search pattern: ”
read r

echo “Enter your search path: ”
read R

echo “Enter file to save to: ”
read i

if grep $r $HOME/$R/* > /dev/null 2>&1 ;
then
cat `grep -l “$r” $HOME/$R/*` | \
sed ‘/Return-Path/,/X-Virus-Checker-Version/d’ >> \
$HOME/bsd/$i.txt
# XXX finish the program!
found=”foo”
else
echo “Can’t find it! Check your search pattern and path.”
# Rerun the search with new pattern and/or path
found=”N”
fi
done

I’d also like to add something at the end of the script where,
even after it finds what I’m looking for and writes it out to my
tips file, it will still come up and ask me if I’d like to enter
a new search. Anyone have a suggestion, please leave a comment.

Cheers!

Labels: , , ,

Friday, July 04, 2008

Fluxbox Article

I've got a new write up on switching desktop wallpaper in
fluxbox automatically on a scheduled basis by using a script
and a cronjob to call it. I also made some additions to my
.kshrc file exporting some values into the environment for
when I login to the system that can be tested against and
also tell fluxbox which one of my wallpaper files to load
when it's starting.

Fluxbox Desktop

Labels: , , , , , , , ,

Monday, January 07, 2008

Recent Web Site Update

I was reading an article by Dru Lavigne at:

Hack #51. Get the Most Out of FTP

I used the info on .netrc along with a script I put together to
login anonymously automatically, get a directory listing of the
packages and diff it against a earlier existing directory listing
in my home directory to see if any packages had been updated.
It was fun as I went along, learing more about scripting and
command line ftp.
More Packages

powered by performancing firefox

Labels: , , , ,