<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: sysadmin code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Sun, 18 May 2008 08:49:24 GMT</pubDate>
    <description>DZone Snippets: sysadmin code</description>
    <item>
      <title>Linux Shell script to rename files</title>
      <link>http://snippets.dzone.com/posts/show/5192</link>
      <description>Before rename command I was using following shell script to rename my mp3s&lt;br /&gt;&lt;code&gt;&lt;br /&gt;#!/bin/bash&lt;br /&gt;# To remove blank space&lt;br /&gt;if [ $# -eq 0 ];&lt;br /&gt;then&lt;br /&gt; echo "Syntax: $(basename $0) file-name [command]"&lt;br /&gt; exit 1&lt;br /&gt;fi&lt;br /&gt;FILES=$1&lt;br /&gt;CMD=$2&lt;br /&gt;for i in $FILES&lt;br /&gt;do&lt;br /&gt;# remove all blanks and store them OUT&lt;br /&gt;OUT=$(echo $i | sed 's/  *//g')&lt;br /&gt;if [ "$CMD" == "" ];&lt;br /&gt;then&lt;br /&gt;#just show file&lt;br /&gt;echo $OUT&lt;br /&gt;else&lt;br /&gt;#else execute command such as mv or cp or rm&lt;br /&gt;[ "$i" != "$OUT" ] &amp;&amp; $($CMD  "$i"  "$OUT")&lt;br /&gt;fi&lt;br /&gt;done&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Sun, 02 Mar 2008 16:13:16 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5192</guid>
      <author>flynets (Flynets is an italian student of computer science with passion for GNU/Linux and hacktivism.)</author>
    </item>
    <item>
      <title>Block many users in a system v0.1.1</title>
      <link>http://snippets.dzone.com/posts/show/5191</link>
      <description>Block many users in a system using a text file as argument&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;#!/bin/bash&lt;br /&gt;&lt;br /&gt;#******************************************************************************#&lt;br /&gt;# BlockManyUsers.sh - Block many users in a system using a text file           #&lt;br /&gt;#                       as argument                                            #&lt;br /&gt;#   Copyright (C) 2008 - written by flynets - &lt;flynets&lt;at&gt;autistici&lt;dot&gt;org&gt;   #&lt;br /&gt;#   BlockManyUsers is free software: you can redistribute it and/or modify     #&lt;br /&gt;#   it under the terms of the GNU General Public License as published by       #&lt;br /&gt;#   the Free Software Foundation, either version 3 of the License, or          #&lt;br /&gt;#   any later version.                                                         #&lt;br /&gt;#                                                                              #&lt;br /&gt;#   BlockManyUsers is distributed in the hope that it will be useful,          #&lt;br /&gt;#   but WITHOUT ANY WARRANTY; without even the implied warranty of             #&lt;br /&gt;#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the               #&lt;br /&gt;#   GNU General Public License for more details.                               #&lt;br /&gt;#                                                                              #&lt;br /&gt;#   You should have received a copy of the GNU General Public License          #&lt;br /&gt;#   along with this program.  If not, see &lt;http://www.gnu.org/licenses/&gt;.      #&lt;br /&gt;#******************************************************************************#&lt;br /&gt;&lt;br /&gt;# Checks if you have the right privileges&lt;br /&gt;if [ "$USER" = "root" ];then&lt;br /&gt;   # Checks if there is an argument&lt;br /&gt;   [ $# -eq 0 ] &amp;&amp; { echo &gt;&amp;2 ERROR: You may enter as an argument a text file containing users, one per line. ; exit 1; }&lt;br /&gt;   # checks if there a regular file&lt;br /&gt;   [ -f "$1" ] || { echo &gt;&amp;2 ERROR: The input file does not exists. ; exit 1; }&lt;br /&gt;   TMPIN=$(mktemp)&lt;br /&gt;   # Remove blank lines and delete duplicates&lt;br /&gt;   sed '/^$/d' "$1"| sort -g | uniq &gt; "$TMPIN"&lt;br /&gt;   &lt;br /&gt;   NOW=$(date +"%Y-%m-%d-%X")&lt;br /&gt;   LOGFILE="BMU-log-$NOW.log"&lt;br /&gt;&lt;br /&gt;   for user in $(more "$TMPIN"); do&lt;br /&gt;      # Checks if the user already exists.&lt;br /&gt;      cut -d: -f1 /etc/passwd | grep "$user" &gt; /dev/null&lt;br /&gt;      OUT=$?&lt;br /&gt;      if [ $OUT -eq 0 ];then&lt;br /&gt;         # block selected user&lt;br /&gt;         /usr/sbin/usermod -L "$user"&lt;br /&gt;         # save user info in a file&lt;br /&gt;         echo The user \"$user\" has been blocked. &gt;&gt; "$LOGFILE"&lt;br /&gt;      else&lt;br /&gt;        echo &gt;&amp;2 Error the user account \"$user\" doesnt exists! &gt;&gt; "$LOGFILE"&lt;br /&gt;      fi&lt;br /&gt;   done&lt;br /&gt;   rm -f $TMPIN&lt;br /&gt;   exit 0&lt;br /&gt;else&lt;br /&gt;   echo &gt;&amp;2 ERROR: You must be a root user to execute this script.&lt;br /&gt;   exit 1&lt;br /&gt;fi&lt;br /&gt;exit 0&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Sun, 02 Mar 2008 14:23:38 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5191</guid>
      <author>flynets (Flynets is an italian student of computer science with passion for GNU/Linux and hacktivism.)</author>
    </item>
    <item>
      <title>Add many users in a Debian system v0.2</title>
      <link>http://snippets.dzone.com/posts/show/4980</link>
      <description>Create many users in a Debian system using a text file as argument&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;#!/bin/bash&lt;br /&gt;&lt;br /&gt;#******************************************************************************#&lt;br /&gt;# AddManyUsers-deb.sh - Create many users in a Debian system using a text file #&lt;br /&gt;# 			as argument					       #&lt;br /&gt;#   Copyright (C) 2008 - written by flynets - &lt;flynets&lt;at&gt;autistici&lt;dot&gt;org&gt;   # &lt;br /&gt;#   AddManyUsers-deb is free software: you can redistribute it and/or modify   #&lt;br /&gt;#   it under the terms of the GNU General Public License as published by       #&lt;br /&gt;#   the Free Software Foundation, either version 3 of the License, or          #&lt;br /&gt;#   any later version.							       #&lt;br /&gt;#									       #&lt;br /&gt;#   AddManyUsers-deb is distributed in the hope that it will be useful,	       #&lt;br /&gt;#   but WITHOUT ANY WARRANTY; without even the implied warranty of             #&lt;br /&gt;#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the	       #&lt;br /&gt;#   GNU General Public License for more details.			       #&lt;br /&gt;#									       #&lt;br /&gt;#   You should have received a copy of the GNU General Public License	       #&lt;br /&gt;#   along with this program.  If not, see &lt;http://www.gnu.org/licenses/&gt;.      #&lt;br /&gt;#******************************************************************************#&lt;br /&gt;&lt;br /&gt;# Checks if you have the right privileges&lt;br /&gt;if [ "$USER" = "root" ]&lt;br /&gt;then&lt;br /&gt;&lt;br /&gt;# CHANGE THIS PARAMETERS FOR A PARTICULAR USE&lt;br /&gt;PERS_HOME="/home/"&lt;br /&gt;PERS_SH="/bin/bash"&lt;br /&gt;&lt;br /&gt;   # Checks if there is an argument&lt;br /&gt;   [ $# -eq 0 ] &amp;&amp; { echo &gt;&amp;2 ERROR: You may enter as an argument a text file containing users, one per line. ; exit 1; }&lt;br /&gt;   # checks if there a regular file&lt;br /&gt;   [ -f "$1" ] || { echo &gt;&amp;2 ERROR: The input file does not exists. ; exit 1; }&lt;br /&gt;   TMPIN=$(mktemp)&lt;br /&gt;   # Remove blank lines and delete duplicates &lt;br /&gt;   sed '/^$/d' "$1"| sort -g | uniq &gt; "$TMPIN"&lt;br /&gt;   &lt;br /&gt;   NOW=$(date +"%Y-%m-%d-%X")&lt;br /&gt;   LOGFILE="AMU-log-$NOW.log"&lt;br /&gt;   &lt;br /&gt;   for user in $(more "$TMPIN"); do&lt;br /&gt;      # Checks if the user already exists.&lt;br /&gt;      cut -d: -f1 /etc/passwd | grep "$user" &gt; /dev/null&lt;br /&gt;      OUT=$?&lt;br /&gt;      if [ $OUT -eq 0 ];then&lt;br /&gt;   	 echo &gt;&amp;2 "ERROR: User account: \"$user\" already exists."&lt;br /&gt;	 echo &gt;&amp;2 "ERROR: User account: \"$user\" already exists." &gt;&gt; "$LOGFILE"&lt;br /&gt;      else&lt;br /&gt;	 # Create a new user&lt;br /&gt;         /usr/sbin/useradd -d "$PERS_HOME""$user" -s "$PERS_SH" -m "$user"&lt;br /&gt;	 # gpw must be installed on debian system&lt;br /&gt;	 pass=$(gpw 1 8)&lt;br /&gt;         echo $user:$pass | chpasswd&lt;br /&gt;	 # save user and password in a file&lt;br /&gt;	 echo -e $user"\t"$pass &gt;&gt; "$LOGFILE"&lt;br /&gt;	 echo "The user \"$user\" has been created and has the password: $pass"&lt;br /&gt;      fi&lt;br /&gt;   done&lt;br /&gt;   rm -f "$TMPIN"&lt;br /&gt;   exit 0&lt;br /&gt;else&lt;br /&gt;   echo &gt;&amp;2 "ERROR: You must be a root user to execute this script."&lt;br /&gt;   exit 1&lt;br /&gt;fi&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Sun, 13 Jan 2008 17:25:42 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4980</guid>
      <author>flynets (Flynets is an italian student of computer science with passion for GNU/Linux and hacktivism.)</author>
    </item>
    <item>
      <title>Add many users in a Red Hat system v0.2</title>
      <link>http://snippets.dzone.com/posts/show/4979</link>
      <description>Create many users in a RedHat system using a text file as argument&lt;br /&gt;&lt;code&gt;&lt;br /&gt;#!/bin/bash&lt;br /&gt;&lt;br /&gt;#******************************************************************************#&lt;br /&gt;# AddManyUsers-rh.sh - Create many users in a Red Hat system using a text file #&lt;br /&gt;# 			as argument					       #&lt;br /&gt;#   Copyright (C) 2008 - written by flynets - &lt;flynets&lt;at&gt;autistici&lt;dot&gt;org&gt;   # &lt;br /&gt;#   AddManyUsers-rh is free software: you can redistribute it and/or modify    #&lt;br /&gt;#   it under the terms of the GNU General Public License as published by       #&lt;br /&gt;#   the Free Software Foundation, either version 3 of the License, or          #&lt;br /&gt;#   any later version.							       #&lt;br /&gt;#									       #&lt;br /&gt;#   AddManyUsers-rh is distributed in the hope that it will be useful,	       #&lt;br /&gt;#   but WITHOUT ANY WARRANTY; without even the implied warranty of             #&lt;br /&gt;#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the	       #&lt;br /&gt;#   GNU General Public License for more details.			       #&lt;br /&gt;#									       #&lt;br /&gt;#   You should have received a copy of the GNU General Public License	       #&lt;br /&gt;#   along with this program.  If not, see &lt;http://www.gnu.org/licenses/&gt;.      #&lt;br /&gt;#******************************************************************************#&lt;br /&gt;&lt;br /&gt;# Checks if you have the right privileges&lt;br /&gt;if [ "$USER" = "root" ]&lt;br /&gt;then&lt;br /&gt;&lt;br /&gt;# CHANGE THIS PARAMETERS FOR A PARTICULAR USE&lt;br /&gt;PERS_HOME="/home/"&lt;br /&gt;PERS_SH="/bin/bash"&lt;br /&gt;&lt;br /&gt;   # Checks if there is an argument&lt;br /&gt;   [ $# -eq 0 ] &amp;&amp; { echo &gt;&amp;2 ERROR: You may enter as an argument a text file containing users, one per line. ; exit 1; }&lt;br /&gt;   # checks if there a regular file&lt;br /&gt;   [ -f "$1" ] || { echo &gt;&amp;2 ERROR: The input file does not exists. ; exit 1; }&lt;br /&gt;   TMPIN=$(mktemp)&lt;br /&gt;   # Remove blank lines and delete duplicates &lt;br /&gt;   sed '/^$/d' "$1"| sort -g | uniq &gt; "$TMPIN"&lt;br /&gt;   &lt;br /&gt;   NOW=$(date +"%Y-%m-%d-%X")&lt;br /&gt;   LOGFILE="AMU-log-$NOW.log"&lt;br /&gt;   &lt;br /&gt;   for user in $(more "$TMPIN"); do&lt;br /&gt;      # Checks if the user already exists.&lt;br /&gt;      cut -d: -f1 /etc/passwd | grep "$user" &gt; /dev/null&lt;br /&gt;      OUT=$?&lt;br /&gt;      if [ $OUT -eq 0 ];then&lt;br /&gt;   	 echo &gt;&amp;2 "ERROR: User account: \"$user\" already exists."&lt;br /&gt;	 echo &gt;&amp;2 "ERROR: User account: \"$user\" already exists." &gt;&gt; "$LOGFILE"&lt;br /&gt;      else&lt;br /&gt;	 # Create a new user&lt;br /&gt;         /usr/sbin/useradd -d "$PERS_HOME""$user" -s "$PERS_SH" -m "$user"&lt;br /&gt;	 # passwdgen must be installed&lt;br /&gt;	 pass=$(passwdgen -paq --length 8)&lt;br /&gt;         echo $pass | passwd --stdin $user&lt;br /&gt;	 # save user and password in a file&lt;br /&gt;	 echo -e $user"\t"$pass &gt;&gt; "$LOGFILE"&lt;br /&gt;	 echo "The user \"$user\" has been created and has the password: $pass"&lt;br /&gt;      fi&lt;br /&gt;   done&lt;br /&gt;   rm -f "$TMPIN"&lt;br /&gt;   exit 0&lt;br /&gt;else&lt;br /&gt;   echo &gt;&amp;2 "ERROR: You must be a root user to execute this script."&lt;br /&gt;   exit 1&lt;br /&gt;fi&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Sun, 13 Jan 2008 17:21:34 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4979</guid>
      <author>flynets (Flynets is an italian student of computer science with passion for GNU/Linux and hacktivism.)</author>
    </item>
    <item>
      <title>Simple mySQL backup script for cron</title>
      <link>http://snippets.dzone.com/posts/show/4172</link>
      <description>Simple mySQL backup script for cron - backs up all databases, saves the last 4 copies.&lt;br /&gt;&lt;code&gt;&lt;br /&gt;#!/bin/bash&lt;br /&gt;&lt;br /&gt;# modify the following to suit your environment&lt;br /&gt;export DB_BACKUP="/backup/mysql_backup"&lt;br /&gt;export DB_USER="root"&lt;br /&gt;export DB_PASSWD="********"&lt;br /&gt;&lt;br /&gt;# title and version&lt;br /&gt;echo ""&lt;br /&gt;echo "mySQL_backup"&lt;br /&gt;echo "----------------------"&lt;br /&gt;echo "* Rotating backups..."&lt;br /&gt;rm -rf $DB_BACKUP/04&lt;br /&gt;mv $DB_BACKUP/03 $DB_BACKUP/04&lt;br /&gt;mv $DB_BACKUP/02 $DB_BACKUP/03&lt;br /&gt;mv $DB_BACKUP/01 $DB_BACKUP/02&lt;br /&gt;mkdir $DB_BACKUP/01 &lt;br /&gt;&lt;br /&gt;echo "* Creating new backup..."&lt;br /&gt;mysqldump --user=$DB_USER --password=$DB_PASSWD --all-databases | bzip2 &gt; $DB_BACKUP/01/mysql-`date +%Y-%m-%d`.bz2&lt;br /&gt;echo "----------------------"&lt;br /&gt;echo "Done"&lt;br /&gt;exit 0&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Wed, 20 Jun 2007 15:01:39 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4172</guid>
      <author>fak3r (fak3r)</author>
    </item>
    <item>
      <title>PHP - Change Active Directory Password</title>
      <link>http://snippets.dzone.com/posts/show/4059</link>
      <description>&lt;code&gt;&lt;br /&gt;&lt;?php&lt;br /&gt;$username=$_POST['user_name'];&lt;br /&gt;//print $username;&lt;br /&gt;&lt;br /&gt;$ldap = ldap_connect($config['ldapServers'], 636);&lt;br /&gt;ldap_set_option($ldap, LDAP_OPT_PROTOCOL_VERSION, 3);&lt;br /&gt;ldap_set_option($ldap, LDAP_OPT_REFERRALS, 0);&lt;br /&gt;  if ($ldap)&lt;br /&gt;{&lt;br /&gt;$bind = ldap_bind($ldap, $config['ldapUsername'], $config['ldapPassword']);&lt;br /&gt;$filter="(sAMAccountName=$username)";&lt;br /&gt;$result = ldap_search($ldap,"dc=yourcompany,dc=com",$filter);&lt;br /&gt;//var_dump($results); &lt;br /&gt;        ldap_sort($ldap,$result,"sn");&lt;br /&gt;       $info = ldap_get_entries($ldap, $result);&lt;br /&gt;       for ($i=0; $i&lt;$info["count"]; $i++)&lt;br /&gt;       {&lt;br /&gt;echo "&lt;p&gt;You are changing the password for &lt;b&gt; ". $info[$i]["givenname"][0] .", " . $info[$i]["sn"][0] ."&lt;/b&gt; (" . $info[$i]["samaccountname"][0] .") to &lt;b&gt;" . $_POST['user_pass'] ."&lt;/b&gt;&lt;/p&gt;\n";&lt;br /&gt;             $passwd1 = $_POST['user_pass'];&lt;br /&gt;              $userDn = $info[$i]["distinguishedname"][0];&lt;br /&gt;              $newPassword = $passwd1;&lt;br /&gt;      $newPassword = "\"" . $newPassword . "\"";&lt;br /&gt;      $len = strlen($newPassword);&lt;br /&gt;      for ($i = 0; $i &lt; $len; $i++){&lt;br /&gt;            $newPassw .= "{$newPassword{$i}}\000";}&lt;br /&gt;      $newPassword = $newPassw;&lt;br /&gt;      $userdata["unicodePwd"] = $newPassword;&lt;br /&gt;      $result = ldap_mod_replace($ldap, $userDn , $userdata);&lt;br /&gt;      if ($result) echo "Your password has been changed!" ;&lt;br /&gt;      else echo "There was a problem changing your password, please call IT for help"; &lt;br /&gt; }&lt;br /&gt;         }&lt;br /&gt;        @ldap_close($ldap);&lt;br /&gt;?&gt;&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Wed, 23 May 2007 18:13:47 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4059</guid>
      <author>amandaemily (Amanda Emily)</author>
    </item>
    <item>
      <title>Perl - Cisco VLAN Removal</title>
      <link>http://snippets.dzone.com/posts/show/4058</link>
      <description>// Perl - Cisco VLAN Removal&lt;br /&gt;// new.txt format &lt;br /&gt;// ipaddress|loginpass|enablepass|gigabitEthernet3/48|20&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;#!c:/perl/bin/perl.exe&lt;br /&gt;&lt;br /&gt;use Net::Telnet::Cisco;&lt;br /&gt;&lt;br /&gt;open(CISCO,'new.txt');&lt;br /&gt; while (&lt;CISCO&gt;) {&lt;br /&gt; chomp;&lt;br /&gt;my @fields = split(/\|/, $_);&lt;br /&gt;&lt;br /&gt;my $host = $fields[0];&lt;br /&gt;my $login = $fields[1];&lt;br /&gt;my $telnet = $fields[2];&lt;br /&gt;my $interface = $fields[3];&lt;br /&gt;my $vlan = $fields[4];&lt;br /&gt;&lt;br /&gt;#print "Content-type:text/html\n\n";&lt;br /&gt;#print "Switch = &lt;b&gt;$host&lt;/b&gt;    &lt;br&gt;";&lt;br /&gt;#print "Command =  &lt;b&gt;username $macaddr password $macaddr&lt;/b&gt;  &lt;br&gt;";&lt;br /&gt;&lt;br /&gt;$session = Net::Telnet::Cisco-&gt;new(Host =&gt; "$host", Input_log =&gt; "input.log");&lt;br /&gt;$session-&gt;login(Password =&gt; "$login");&lt;br /&gt;$session-&gt;enable("$telnet");&lt;br /&gt;$session-&gt;cmd("config t");&lt;br /&gt;$session-&gt;cmd("int $interface");&lt;br /&gt;$session-&gt;cmd("no switchport access vlan $vlan");&lt;br /&gt;$session-&gt;cmd("no switchport mode access");&lt;br /&gt;$session-&gt;cmd("exit");&lt;br /&gt;$session-&gt;close();&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Wed, 23 May 2007 18:09:33 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4058</guid>
      <author>amandaemily (Amanda Emily)</author>
    </item>
    <item>
      <title>Perl - Cisco Wireless Managment</title>
      <link>http://snippets.dzone.com/posts/show/4057</link>
      <description>// Perl script to update MAC access table on Cisco IOS-based AiroNets&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;#!c:/perl/bin/perl.exe&lt;br /&gt;&lt;br /&gt;# Update Aironet IOS mac addresses&lt;br /&gt;&lt;br /&gt;use Net::Telnet::Cisco;&lt;br /&gt;use vars qw($r @data);&lt;br /&gt;&lt;br /&gt;print "Content-type:text/html\n\n";&lt;br /&gt;&lt;br /&gt;read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});&lt;br /&gt;@pairs = split(/&amp;/, $buffer);&lt;br /&gt;foreach $pair (@pairs) {&lt;br /&gt;    ($name, $value) = split(/=/, $pair);&lt;br /&gt;    $value =~ tr/+/ /;&lt;br /&gt;    $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;&lt;br /&gt;    $FORM{$name} = $value;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;$macaddr = $FORM{'command'};&lt;br /&gt;#$macaddr = 'AABBCCDDEEFF';&lt;br /&gt;&lt;br /&gt;print "using command &lt;u&gt;username &lt;b&gt;$macaddr&lt;/b&gt; password &lt;b&gt;0$macaddr&lt;/b&gt;&lt;/u&gt;&lt;br&gt;&lt;br&gt;";&lt;br /&gt;&lt;br /&gt;	&lt;br /&gt;print "Updating AP &lt;b&gt;127.0.0.1 (conference center)&lt;/b&gt;    &lt;br&gt;";&lt;br /&gt;$r = Net::Telnet::Cisco-&gt;new(Host=&gt;"127.0.0.1");&lt;br /&gt;	$r-&gt;login("login","password");&lt;br /&gt;die($r-&gt;errmsg) unless($r-&gt;enable("password"));&lt;br /&gt;	$r-&gt;cmd('terminal length 0');&lt;br /&gt;	$r-&gt;cmd('config t');&lt;br /&gt;	$r-&gt;cmd("username $macaddr password $macaddr");&lt;br /&gt;	$r-&gt;cmd("username $macaddr autocommand exit");&lt;br /&gt;	$r-&gt;cmd("exit");&lt;br /&gt;	$r-&gt;cmd("write memory quiet");&lt;br /&gt;	$r-&gt;cmd('terminal length 24');&lt;br /&gt;	$r-&gt;close();&lt;br /&gt;print "Done!";&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Wed, 23 May 2007 18:06:00 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4057</guid>
      <author>amandaemily (Amanda Emily)</author>
    </item>
    <item>
      <title>command to install mysql gem in FC5</title>
      <link>http://snippets.dzone.com/posts/show/3186</link>
      <description>// installs the mysql gem with the correct locations of the mysql  install, for some reason the installer can't find it on its own.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;gem install mysql -- --with-mysql-include=/usr/include/mysql --with-mysql-lib=/usr/lib/mysql&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Thu, 21 Dec 2006 00:25:21 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/3186</guid>
      <author>adevadeh (adeh)</author>
    </item>
    <item>
      <title>Simple process watchdog</title>
      <link>http://snippets.dzone.com/posts/show/1737</link>
      <description>I had a problem where an important monitoring daemon was committing sepuku every night between 3 and 4 am. While debugging it, I whipped up the script below.&lt;br /&gt;&lt;br /&gt;Basically, it checks to see if the process ID file is present, and if it is, checks that the process is actually running. If not, it invokes the restart command.&lt;br /&gt;&lt;br /&gt;It outputs info to syslog so you can check it out the next day.&lt;br /&gt;&lt;br /&gt;Written in perl, requires Sys::Syslog. Tested on Linux (your ps command details may vary on other unices). Not worth bothering with this on windows.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;#!/usr/bin/perl&lt;br /&gt;&lt;br /&gt;use Sys::Syslog qw(:standard :macros);&lt;br /&gt;&lt;br /&gt;my $pidfile = "/usr/local/bs/adm/uxmon.pid";&lt;br /&gt;my $check_command = "uxmon";&lt;br /&gt;my $start_command = "/etc/init.d/bigsister restart";&lt;br /&gt;&lt;br /&gt;openlog("ProcessWatcher", "pid",LOG_LOCAL0);&lt;br /&gt;&lt;br /&gt;if (! -e $pidfile) {&lt;br /&gt;    syslog(LOG_WARNING, "Process ID file not found, restarting application");&lt;br /&gt;    &amp;restart_proc;&lt;br /&gt;    exit;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;open (IN, $pidfile) || syslog(LOG_ERR, "Couldn't read $pidfile- $!");&lt;br /&gt;my $pid = &lt;IN&gt;;&lt;br /&gt;chomp $pid;&lt;br /&gt;&lt;br /&gt;my $ret = `ps -p $pid -o comm=`;&lt;br /&gt;if ($ret != $check_command) {&lt;br /&gt;    syslog(LOG_ERR, "Return value mismatch, restarting Process");&lt;br /&gt;    &amp;restart_proc;&lt;br /&gt;    exit;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;sub restart_proc() {&lt;br /&gt;    my $msg = `$start_command`;&lt;br /&gt;    syslog (LOG_INFO, "Restarting Process returned: $msg");&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Thu, 23 Mar 2006 19:20:21 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/1737</guid>
      <author>thowland (Tim Howland)</author>
    </item>
  </channel>
</rss>
