Jan
27

Bonding Network Interfaces in Debian

Awhile back I posted  how to do this in gentoo… I did this a couple days ago on debian and thought I woudl post it as well…

First install ifenslave…

apt-get install ifenslave

Then modify your configuration in /etc/network/interfaces (you may want to stop your interfaces prior to this if you don’t want to reboot) …

auto bond0

iface bond0 inet static
    address 10.31.1.5
    netmask 255.255.255.0
    network 10.31.1.0
    gateway 10.31.1.254
    slaves eth0 eth1
    bond-mode active-backup
    bond-miimon 100
    bond-downdelay 200
    bond-updelay 200

Then you either reboot or start the interface if you already stopped eth0 and eth1 prior to removing their configuration from the file.

Jan
06

Updating Samba – Duplicate UID’s

So over christmas break, I updated samba on the high school’s server and after I finally got kerberos working properly again (can’t use IP addresses in the updated krb5 configuration) and I thought everything was good to go… about 1/2 the students can’t access thier My Documents any l longer.  Come to find out that there were multiple users with the same uid.  I did the logical thing and deleted the idmap tdb’s in /var/lib/samba.  I even unmerged and emerged again removing the entire /var/lib/samba dir.  I changed the idmaping range and it still would not reassign idmaps to all users.  Of course I brough this up on #freenode with no reply.  Finaly I decided to do it manually with wbinfo and I wrote a script to do the whole thing.

#!/bin/bash
wbinfo -u > users.txt
wbinfo -g > groups.txt
rm setidmap-uid.sh
rm setidmap-gid.sh

while read line;
do
  echo "Find SID for: $line"
  sid=$(wbinfo -n $line | cut -d ' ' -f1)
  echo "SID = $sid"
  if [ $sid != "" ]; then
    uid=$(wbinfo --allocate-uid | cut -d ' ' -f3)
    echo "New UID = $uid"
    ouid=$(wbinfo -S $sid)
    echo "Old UID = $ouid"
    echo "Set idmap with: wbinfo --set-uid-mapping=$uid,$sid"
    echo "wbinfo --set-uid-mapping=$uid,$sid" >> setidmap-uid.sh
    echo "wbinfo -U $uid" >> setidmap-uid.sh
   fi
done < users.txt

while read line;
do
  echo "Find SID for: $line"
  sid=$(wbinfo -n $line | cut -d ' ' -f1)
  echo "SID = $sid"
  if [ $sid != "" ]; then
    gid=$(wbinfo --allocate-gid | cut -d ' ' -f3)
    echo "New GID = $gid"
    echo "Set idmap with: wbinfo --set-gid-mapping=$gid,$sid"
    echo "wbinfo --set-gid-mapping=$gid,$sid" >> setidmap-gid.sh
    echo "wbinfo -G $gid" >> setidmap-gid.sh
  fi
done < groups.txt

chmod 755 setidmap-gid.sh
chmod 755 setidmap-uid.sh
./setidmap-gid.sh
./setidmap-uid.sh
./fixhomedirs.sh

So this script gets a listing of all users and groups from wbinfo and puts them in a text file.  It then loops through each user, getting its SID and finding the first available UID and creates a script that when called with create the new map and do an SID lookup from the UID.  I am not sure why the uid -> SID lookup is required but nsswitch didn’t see the new idmap until after I did this.  I then loops through the groups and does the same thing with gid’s.  Finally it calls my fix home directory script to assing the proper permissions back to the users. That is posted here: http://blog.adrenlinerush.net/?p=50

I ran this following a removal of the idmap and idmap cahce tdb files and a restat of the samba/winbind services.  This did reset the idmap count so it started at the lowest number in the confuration file.  Not really mandatory but a little cleaner than if you don’t.  I’m guessing that the idmapping’s are stored elswhere and could be removed and not have to run the script, and if someone knows where that is please comment.

 

May
18

LibreOffice Debian 6

So getting my automated install ready for this summer, Debian does not have Libre in their repositories as of yet and I have yet to find one containing it… I found one for Ubuntu that doesn’t work though…  why anyone runs that disgusting distro I don’t know.  Anyways I downloaded the .debs and placed them on my web server and wrote a little script that determines whether its 64bit or 32bit and installs the proper package.  I changed the links on my script to use their mirrors so you can use it as is…

# Install Libre Office
MACHINE_TYPE=`uname -m`
if [ ${MACHINE_TYPE} == 'i686' ];
then
        wget http://download.documentfoundation.org/libreoffice/stable/3.3.2/deb/x86/LibO_3.3.2_Linux_x86_install-deb_en-US.tar.gz
        tar xvf LibO_3.3.2_Linux_x86_install-deb_en-US.tar.gz
        cd LibO_3.3.2rc2_Linux_x86_install-deb_en-US/DEBS
        dpkg -i ./*.deb
        cd desktop-integration
        dpkg -i ./*.deb
        cd ../../../
        rm -rf LibO_3.3.2rc2_Linux_x86_install-deb_en-US
        rm -rf LibO_3.3.2_Linux_x86_install-deb_en-US.tar.gz
else
        wget http://download.documentfoundation.org/libreoffice/stable/3.3.2/deb/x86_64/LibO_3.3.2_Linux_x86-64_install-deb_en-US.tar.gz
        tar xvf LibO_3.3.2_Linux_x86-64_install-deb_en-US.tar.gz
        cd LibO_3.3.2rc2_Linux_x86-64_install-deb_en-US/DEBS
        dpkg -i ./*.deb
        cd desktop-integration
        dpkg -i ./*.deb
        cd ../../../
        rm -rf LibO_3.3.2rc2_Linux_x86-64_install-deb_en-US
        rm -rf LibO_3.3.2_Linux_x86-64_install-deb_en-US.tar.gz
fi

 

 

May
17

Laptop Setup for Offline Authentication and End User Wireless Management

For Linux to deployable to an end user in an enterprise environment a couple of things need to happen.  First they need to be able to log in whether they can see the server to authenticate or not.  We still have an Active Directory domain here in Orion so I needed to allow windows users to be able to cache their credentials.  Assuming winbind is setup and authenticating you simply need to add a setting to smb.conf, a setting to pam and finally restart samba.  Here’s a script that will do it for you.

echo "winbind offline logon = yes" >> /etc/samba/smb.conf
echo "[global]
cached_login = yes" >> /etc/security/pam_winbind.conf
/etc/init.d/winbind restart

Then you can log in once, logout, disconnect from the network and test to ensure that you can authenticate offline.

The second thing that is needed is for the end user to be able to manage their wireless connection.  Most of the hardware I get to deploy Linux on is older and mainly because of the ability to streamline the OS.  This is the case with desktop deployment anyway, however almost all servers I implement are Linux.  With old hardware I like to use lightweight utilities so wpa supplicants build in gui makes sense to use.  However it cannot access the service as a normal user.  We will use sudo for this and make a Desktop shortcut to lauch it.

#install the software needed
#Debian
apt-get -y install sudo wpagui
#Gentoo
emerge -va sudo wpa_supplicant
#allow all user to run wpa_gui with sudo and no password
echo"ALL	ALL = NOPASSWD:/usr/sbin/wpa_gui" >> /etc/sudoers

#Create the Desktop folder in skeleton if it doesn't exist already
mkdir /etc/skel/Desktop

#Create the Desktop launcher for wpa
cd /etc/skel/Desktop
echo "[Desktop Entry]
Encoding=UTF-8
Version=1.0
Type=Application
Terminal=false
Exec=sudo /usr/sbin/wpa_gui
Name[en_US]=Wireless Tool
Icon[en_US]=/usr/share/pixmaps/wpa_gui.xpm" > Wireless.desktop

Finally you’ll want to configure the wireless card and default network or networks.  To do this first generate the psk for your SSID using wpa_passphrase:

austin@stilsuit:~$ wpa_passphrase YOUR_SSID
# reading passphrase from stdin
your_password
network={
	ssid="YOUR_SSID"
	#psk="your_password"
	psk=7678b7cf3fa74dac4f7f75a33c9f32782bf001c4b39571885215800338befcd6
}

Then on a Debian System you will edit /etc/network/interfaces and add something like the following:

auto wlan0
iface wlan0 inet dhcp
    wpa-ssid YOUR_SSID
    wpa-psk 7678b7cf3fa74dac4f7f75a33c9f32782bf001c4b39571885215800338befcd6
    # force WPA-PSK TKIP
    wpa-key_mgmt WPA-PSK
    wpa-proto WPA
    wpa-pairwise TKIP
    wpa-group TKIP

If you are on a Gentoo System you’ll need to edit /etc/conf.d/net:

modules=( "wpa_supplicant" )
wpa_supplicant_wlan0="-Dwext"
wpa_timeout_wlan0=15

and /etc/wpa_supplicant/wpa_supplicant.conf:

# The below line not be changed otherwise we refuse to work
ctrl_interface=/var/run/wpa_supplicant

# Ensure that only root can read the WPA configuration
ctrl_interface_group=0

# Let wpa_supplicant take care of scanning and AP selection
ap_scan=1

network={
	ssid="YOUR_SSID"
	#psk="your_password"
	psk=7678b7cf3fa74dac4f7f75a33c9f32782bf001c4b39571885215800338befcd6
}

Now you should be able to have anyone use the wpa_gui and have a shortcut on their desktop.  Well the shortcut is in the skeleton file so only new homes will get it copied over.

 

 

May
13

How-to Create Preseed Answer Script For Debian

Step 1: Build a System the way you want to auto install them.

Step 2: Get the example preseed script to modify:

Debian 6: http://www.debian.org/releases/squeeze/example-preseed.txt

Step 3: Get the additional answers you will need.  You will need to install debconf-utils package to do this.

apt-get install debconf-utils

debconf-get-selections
debconf-get-selections --installer

Setp 4: Add/modify the example preseed with the information just obtained and by reading comments.

Step 5: Make sure you list any additional packages with the d-i pkgsel/include string:

d-i pkgsel/include string geany lxde cifs-utils mlocate

Step 6: Script any additional changes you may need in a post-preseed.sh script and call it from the late command:

d-i preseed/late_command string \
	in-target wget http://debian.orionschools.us/ohs-postpreseed.sh; \
	in-target /bin/bash -x chmod 755 ./ohs-postpreseed.sh; \
	in-target /bin/bash -x ./ohs-postpreseed.sh;

Step 7: TEST TEST TEST!

Here is what I’ve come up with so far for my Debian 6 preseed.  I’m in the process of debugging now with a couple minor things to work out with tasksel.

d-i debian-installer/locale string en_US
d-i console-keymaps-at/keymap select us
d-i keyboard-configuration/xkb-keymap select us
d-i netcfg/choose_interface select auto
d-i netcfg/get_hostname string temp-hostname
d-i netcfg/get_domain string ORIONCUSD223.local
d-i netcfg/wireless_wep string
d-i hw-detect/load_firmware boolean true
d-i mirror/country string manual
d-i mirror/http/hostname string debian.orionschools.us
d-i mirror/http/directory string /debian
d-i mirror/http/proxy string
d-i passwd/root-password-crypted password md5cryptedpassword
d-i passwd/user-fullname string Austin Mount
d-i passwd/username string austin
d-i passwd/user-password-crypted password md5cryptedpassword
d-i clock-setup/utc boolean false
d-i time/zone string US/Central
d-i clock-setup/ntp boolean true
d-i partman-auto/disk string /dev/sda
d-i partman-auto/method string regular
d-i partman-lvm/device_remove_lvm boolean true
d-i partman-md/device_remove_md boolean true
d-i partman-lvm/confirm boolean true
d-i partman-auto/choose_recipe select atomic
d-i partman-partitioning/confirm_write_new_label boolean true
d-i partman/choose_partition select finish
d-i partman/confirm boolean true
d-i partman/confirm_nooverwrite boolean true
d-i apt-setup/non-free boolean true
d-i apt-setup/contrib boolean true
d-i apt-setup/services-select multiselect security
d-i apt-setup/security_host string debian.orionschools.us/debian-security
d-i apt-setup/local0/repository string \
       http://debian-multimedia.org squeeze main non-free
d-i apt-setup/local0/source boolean true
d-i debian-installer/allow_unauthenticated string true
tasksel	tasksel/first multiselect standard ssh-server
taslsel tasksel/skip-tasks multiselect desktop
#############################################################################################
#										PACKAGES											#
#############################################################################################
d-i pkgsel/include string \
	openssh-server build-essential libpam-mount winbind cifs-utils lsof smbfs xorg-server \
	lxde cups geany acroread gimp inkscape geogebra scribus chromium-browser mplayer vlc \
	flashplugin-nonfree sun-java6-plugin sun-java6-jre mlocate
#############################################################################################
d-i pkgsel/upgrade select full-upgrade
popularity-contest popularity-contest/participate boolean false
d-i lilo-installer/skip boolean true
d-i grub-installer/only_debian boolean true
d-i finish-install/reboot_in_progress note
d-i samba-common/dhcp boolean false
d-i samba-common/workgroup string ORIONCUSD223.local
d-i samba-common/encrypt_passwords boolean true
d-i samba-common/do_debconf boolean true
sun-java6-bin shared/accepted-sun-dlj-v1-1 boolean true
sun-java6-jre shared/accepted-sun-dlj-v1-1 boolean true
sun-java6-jre sun-java6-jre/stopthread boolean true
sun-java6-jre sun-java6-jre/jcepolicy note
sun-java6-bin shared/error-sun-dlj-v1-1 error
sun-java6-jre shared/error-sun-dlj-v1-1 error
sun-java6-bin shared/present-sun-dlj-v1-1 note
sun-java6-jre shared/present-sun-dlj-v1-1 note
#############################################################################################
# 										POST PRESEED 										#
#############################################################################################
d-i preseed/late_command string \
	in-target wget http://debian.orionschools.us/ohs-postpreseed.sh; \
	in-target /bin/bash -x chmod 755 ./ohs-postpreseed.sh; \
	in-target /bin/bash -x ./ohs-postpreseed.sh;
#############################################################################################

And my postpreseed script ….

#!/bin/bash

# Set Hostname per host entries
wget http://debian.orionschools.us/hostnames
mac=$(/sbin/ifconfig | grep 'eth0' | tr -s ' ' | cut -d ' ' -f5)
hostname=$(cat hostnames | grep $mac | cut -d"-" -f2)
echo $hostname > /etc/hostname
hostname $hostname
echo "127.0.0.1		localhost $hostname $hostname.ORIONCUSD223.local" > /etc/hosts
/etc/init.d/hostname.sh
rm -rf hostnames

# Install Libre Office
wget http://debian.orionschools.us/thirdparty_packages/LibO_3.3.2_Linux_x86_install-deb_en-US.tar.gz
tar xvf LibO_3.3.2_Linux_x86_install-deb_en-US.tar.gz
cd LibO_3.3.2rc2_Linux_x86_install-deb_en-US/DEBS
dpkg -i ./*.deb
cd desktop-integration
dpkg -i ./*.deb
cd ../../../
rm -rf LibO_3.3.2rc2_Linux_x86_install-deb_en-US
rm -rf LibO_3.3.2_Linux_x86_install-deb_en-US.tar.gz

# Get skel file
cd /etc/skel
mkdir -p .config/openbox
cd .config/openbox
wget http://debian.orionschools.us/ohs-configs/startup.sh
chmod 755 startup.sh

# Join Samba Domain
cd /etc/samba
mv smb.conf smb.conf.dist
wget http://debian.orionschools.us/ohs-configs/smb.conf
/etc/init.d/winbind restart
net join YOURDOMAIN -S domaincontroller -U 'administrator%YOURPASSWORDHERE'

# Setup Domain auth with PAM
cd /etc
mv nsswitch.conf nswitch.conf.dist
wget http://debian.orionschools.us/ohs-configs/nsswitch.conf

# Setup mydocuments mount
cd /etc/security
mv pam_mount.conf.xml pam_mount.conf.xml.dist
wget http://debian.orionschools.us/ohs-configs/pam_mount.conf.xml

For security reasons I have my post-preseed only on the website when I’m using it and its only available internally which will be that way until I find a good way to encrypt the password for joining the Windows AD Domain.

May
13

Auto-mount and umount on login cifs Debian 6 using pam_mount

So I’m working on my Debian 6 Squeeze setup to deploy in a lab at the High School over the summer and I wanted a nice clean way give users access to their Windows my documents.  In the past I’ve mounted /home via nfs or cifs which has worked well but recently I’ve had issues with the hidden files that applications create.  Google Chrome, Firefox, LibreOffice etc all seem to have issues with this.  I’ve also used mount.cifs with suid on login scripts to provide this functionality (which Debian no longer supports).  Neither have I been 100% satisfied with.  So for this setup I found a couple PAM modules that looked promising.  The one I decided to go with was libpam_mount.  This will use the credentials used at login and based on a configuration xml mount directories for users at login via smbfs, cifs, nfs and others.

On Debian 6 you will need to have winbind, cifs-utils, lsof, and libpam-mount installed.  Also this assumes you have winbind configured for authentication against your windows domain already.  Debian will take care of the PAM settings for both winbind and libpam-mount and you will just need to change nsswitch.conf and smb.conf and join it to the domain.

Once you have a working winbind authentication then you can configure /etc/security/pam_mount.conf.xml.  Here is what I’ve come up with to mount the users samba home  (Windows profile) in a hidden directory called .winprofile.

<?xml version="1.0" encoding="UTF-8"?>
<pam_mount>
<debug enable="1" />
<mkmountpoint enable="1" />
<mntoptions allow="nosuid,nodev,loop,encryption,fsck" />
<mntoptions require="nosuid,nodev" />
<lsof>/usr/bin/lsof %(MNTPT)</lsof>
<cifsmount>/sbin/mount.cifs //%(SERVER)/%(VOLUME) %(MNTPT) -o "user=%(USER),domain=ORIONCUSD223,uid=%(USER),gid=ohs_staff"</cifsmount>
<umount>/bin/umount %(MNTPT)</umount>
<volume options="username=%(DOMAIN_USER),workgroup=%(DOMAIN_NAME),uid=%(DOMAIN_USER),fmask=700" mountpoint="~/.winprofile" path="%(DOMAIN_USER)" server="gill" fstype="cifs" />
</pam_mount>

PAM will pass the username and password then along.  You will have to change the server name and domain and group for this to work with your system.

Then I wanted them to see their Windows documents.  For this lab we will be running LXDE so in my post-preseed script I create the openbox config directory in the skeleton file and put a startup script that will create a symlink on login if it doesn’t exist.

cd /etc/skel
mkdir -p .config/openbox
cd .config/openbox
nano startup.sh
#insert the below
chmod 755 startup.sh
cd ~/
if [ ! -f  ~/Desktop/Documents ]
then
  ln -s ~/.winprofile/My\ Documents ~/Desktop/Documents
fi

That should be all you need to have your Windows profile auto mounted an umounted with each login and logout and you will have a folder on your desktop called Documents to access the Windows My Documents folder.

 

May
09

Importing existing balances into PSCafePOS

The school I work for will be changing their lunch software at the end of this year and I’m pushing for using the open source software PSCafePOS.  It will do everything we want to out of the box with the exception of online payments.  Most likely when we switch student information systems next year the new one will be used to provide this functionality.  Otherwise, I will write Paypal integration which I have done for several other projects.  Anyway, in preparation for a demonstration with the superintendent and the head kitchen staff I prepared a system with our existing data to play with.  I wrote the export for school master and used the web interface to import students to the internal SIS and I uploaded photos tot he proper web served location.  I also wrote a script to import initial balances as there isn’t any mechanism supplied for that.  Simply takes the out put from our current system (Lunchbox) that I export of student ID, balance (well without the decimal point) and divides the balance by 100 to give us cents and imports it into PSCafePOS with an initial balance comment in the transaction log.  I thought it may be useful to another school looking to import their balances.

<?php
error_reporting(0);

$file = "balances.csv";
$db_username = "username";
$db_password = "password";
$db_host = "pscafepos";
$db_database = "pscafepos";

require_once('MDB2.php');
$db = MDB2::connect("mysql://$db_username:$db_password@$db_host/$db_database");
if (!MDB2::isError($db)) {
  importBalances($file, $db);
} else {
	echo "DB failed to connect.\n";
}

function importBalances($file, $db)
{
  $balancefile = fopen($file, 'r');
  while (!feof($balancefile))
  {
    $line = fgets($balancefile);
    $items = explode(",",$line);
    $studentid = $items[0];
    $balance = $items[1]/100;
    if ($studentid != "") {
	  if (isStudentInSIS($studentid, $db)) {
	     if(!isStudentCredit($studentid, $db)) {
			insertCredit($studentid, $balance, $db);
	     } else {
			updateCredit($studentid, $balance, $db);
	     }
	     insertInitialCreditLog($studentid,$balance, $db);
	  }
    }
  }
  fclose($balancefile);
} 

function isStudentInSIS($studentid, $db)
{
	$sql = 'Select * from sis_students where sis_studentid = "' . $studentid . '";';
	$rslt = $db->query($sql);
	if ($rslt->fetchRow())
	{
		echo "Student In SIS.  Should Contintue.\n";
		return true;
	} else {
		echo "Student Not in SIS.  Should Move to Next Student.\n";
		return false;
	}
}

function isStudentCredit($studentid, $db)
{
	$sql = 'Select * from studentcredit where credit_studentid = "' . $studentid . '";';
	$rslt = $db->query($sql);
	if ($rslt->fetchRow())
	{
		echo "Student has credit account.\n";
		return true;
	} else {
		echo "Student does not have a credit account.\n";
		return false;
	}
}

function updateCredit($studentid, $balance, $db)
{
	$sql = 'Update studentcredit set credit_amount = "' . $balance . '" where credit_studentid = "' . $studentid . '";';
	$rslt = $db->query($sql);
	if (MDB2::isError($rslt)) {
		echo "Error updating credit balance:" . MDB2::errorMessage($rslt) . "\n";
		die;
	} else {
		echo "Successfully updated credit balance.\n";
	}
	$sql = 'Delete from studentcredit_log where scl_studentid = "' . $studentid . '";';
	$rslt = $db->query($sql);
	if (MDB2::isError($rslt)) {
		echo "Error removing credit log:" . MDB2::errorMessage($rslt) . "\n";
		die;
	} else {
		echo "Successfully removed credit log.\n";
	}
}

function insertCredit ($studentid, $balance, $db)
{
	$sql = 'Insert into studentcredit (credit_studentid, credit_amount, credit_active) Values("' .
		$studentid . '","' . $balance . '","1");';
	$rslt = $db->query($sql);
	if (MDB2::isError($rslt)) {
		echo "Error inserting credit balance: ". MDB2::errorMessage($rslt) . "\n";
		die;
	} else {
		echo "Successfully inserted credit balance.\n";
	}
}

function insertInitialCreditLog ($studentid, $balance, $db)
{
	$sql = 'Insert into studentcredit_log (scl_studentid, scl_action, scl_transid, scl_datetime, scl_description) Values("' .
		$studentid . '","' . $balance . '",0,now(),"Initial Balance");';
	$rslt = $db->query($sql);
	if (MDB2::isError($rslt)) {
		echo "Error inserting credit log: ". MDB2::errorMessage($rslt) . "\n";
		echo $sql . "\n";
		die;
	} else {
		echo "Successfully inserted credit log.\n";
	}
}

?>

May
04

Symbolic links on NTFS

Apparently there are such a thing as symbolic links on NTFS…  I discovered this yesterday as I needed to create the behavior so that student shortcuts could be the same regardless of whether Office was installed on 32bit or 64bit windows and regardless of which version of Office since their start menu is tied to their user.  If I prefer this over group policy user loop processing from the computer policy.  Anyways this is accomplished using the mklink command and there is a switch required for directory symlink (/D).

mklink /D "C:\Program Files\Microsoft Office\Office12" "C:\Program Files (x86)\Microsoft Office\Office14"

This example will make an Office 2007 Path on a 32bit system link to Office 2010 path on a 64bit system.  Then a shortcut you created for Office 2007 will work for 2010!

May
03

Vixiecron Gentoo Editing

It’s been a couple weeks since my last post so I figured I needed to put something on here soon…  I’ve been pretty busy, just ran my second 1/2 marathon on Saturday and cut 34 seconds p/mile of my pace… Now it’s time to get ready for Chicago and concentrate on getting donations for the Leukemia and Lymphoma society.  School is going to be out in a couple weeks too so I am going to have a ton of projects going on to blog about.  Today I did something rather routine for me in added a script to a crontab that I’ve been running manually for a couple months to make sure I have all the bugs out of it.  For someone that is new to Linux/Unix systems a crontab is simply a scheduled task and there are several different cron daemons available.  I run vixiecron on all of my Gentoo servers and have been very happy with it.  Most people install cron during the installation of the OS…

emerge -va vixiecron

Root can run cron jobs without any group additions since it can do anything hence the name root or super user.  All other users need to be a member of the cron group.  As root you can use the gpasswd command to add users to the cron group.

gpasswd -a myuser cron

to edit the crontab of your current user simply type:

crontab -e

This will bring up your default command line editor to manipulate the crontab.  Unless you changed it, this will be nano on a Gentoo system.  As root you can also use the -u option and specify a user.  After it is saved and installed you can use the -l option to “list” the currently installed crontab.

Once in the editor you will need to define when to run the cron job.  I found this self contained cheat sheet awhile back and place it in crontab.

# * * * * * command to be executed
# - - - - -
# | | | | |
# | | | | +- - - - day of week (0 - 6) (Sunday=0)
# | | | +- - - - - month (1 - 12)
# | | +- - - - - - day of month (1 - 31)
# | +- - - - - - - hour (0 - 23)
# +- - - - - - - - minute (0 - 59)

This will do the basics for you but there are options like */5 to run every 5 minutes that are not included in the cheat sheet.  You will then add a line for each command to execute with the proper date and time.  Say you want to run something every night at 11pm from a special directory you can do something like this:

0 23 * * * cd /path/to/run/from && php relative/path/script.php

There it is quick and easy.

Apr
13

Bash Script – Symlinks in home to shared folder

Awhile back I had a couple teachers ask me if they could have a classroom folder that all the students use but only they have access to.  All of the students home folders are on a Linux box and server to windows via samba.  So I wrote this script that reads in usernames and creates symlinks to a directory in the teachers home folder.   The text file that gets passed has one uid per line with the first being the teachers.  You would of course have to adjust the domain to whatever your domain is called.  Saved me a couple hours using this script so I thought I would share.

#!/bin/bash
#
#  bash script to create symbolic link in student folder to teacher shared folder
#

let cnt=0;
teacher=;
cat $1 |
while read uid;
do
        echo "Count: $cnt";
        if [ $cnt -eq 0 ]; then
                teacher=$uid;
                echo "Teacher: $teacher";
        else
                student=$uid;
                echo "uid: $uid";
                echo "Student: $student";
                echo "Executing: ln -s /home/ORIONCUSD223/$teacher/ClassShare /home/ORIONCUSD223/$student/";
                ln -s /home/ORIONCUSD223/$teacher/ClassShare /home/ORIONCUSD223/$student/
        fi
        let cnt+=1;
done

Older posts «