Tag Archive > bash

FreeNAS Bash script to start a ZFS scrub on each pool (scrub.sh)

gimpe » 28 August 2009 » In FreeNAS, bash » 6 Comments

This script will start a scrub on each ZFS pool (one at a time) and will send an e-mail or display the result when everyting is completed. I wrote this script to launch each scrub one after the other and a summary by e-mail that can tell me how much time it took to each ZFS scrub.

Continue reading...

Tags: ,

Useful tools in an “embedded” FreeNAS: wget and bash

gimpe » 04 August 2009 » In FreeNAS, bash » No Comments

wget

To install wget on a “data” parition:

export PKG_TMPDIR=/mnt/usb-data/temp
pkg_add -r wget -P /mnt/usb-data/pkg

Now we need a script to create the symlinks to the wget binaries in the “pkg” directory:

nano /mnt/usb-data/hooks.sh

Here’s the content:

#!/bin/sh

ln -s /mnt/usb-data/pkg/bin/wget /bin/wget

Now make it run at boot time, go in System —> Advanced —> Command scripts and enter:

/mnt/usb-data/hooks.sh

Select PostInit and that’s it! Everytime you reboot your FreeNAS server the symlinks will be re-created!

bash

For bash, add this in the “hooks.sh” script:

# .bashrc for root
ln -s /mnt/usb-data/bashrc /root/.bashrc

# .bashrc for regular user
ln -s /mnt/usb-data/bashrc /mnt/.bashrc

# automatically load bash for root on login (not clean but works)
echo "bash --init-file /mnt/usb-data/bashrc" >> /root/.cshrc

# automatically load bash for regular user on login (not clean but works)
echo "bash --init-file /mnt/usb-data/bashrc" >> /mnt/.cshrc

Continue reading...

Tags: ,

Vim (Vi IMproved) in an “embedded” FreeNAS

gimpe » 03 August 2009 » In FreeNAS, bash » 3 Comments

You need an embedded install with a data partition. My FreeNAS server runs from a 1GB usb stick and the data partition is mounted as “/mnt/usb-data”. To install Vim on the usb stick:

# using csh
setenv PKG_TMPDIR /mnt/usb-data/temp

# install package
pkg_add -r vim-lite -P /mnt/usb-data/pkg

Now we need a script to create the symlinks to the Vim binaries in the “pkg” directory:

nano /mnt/usb-data/hooks.sh

Here’s the content:

#!/bin/sh

# Vim symlinks to binaries
ln -s /mnt/usb-data/pkg/bin/vim /bin/vi
ln -s /mnt/usb-data/pkg/bin/vim /bin/vim

# .vimrc for root
ln -s /mnt/usb-data/pkg/share/vim/vim72/vimrc_example.vim /root/.vimrc
# .vimrc for regular user
ln -s /mnt/usb-data/pkg/share/vim/vim72/vimrc_example.vim /mnt/.vimrc

# syntax file
mkdir  /usr/local/share/vim/
mkdir  /usr/local/share/vim/syntax/
ln -s /mnt/usb-data/pkg/share/vim/vim72/syntax/syntax.vim /usr/local/share/vim/syntax/syntax.vim

Now make it run at boot time, go in System —> Advanced —> Command scripts and enter:

/mnt/usb-data/hooks.sh

Select PostInit and that’s it! Everytime you reboot your FreeNAS server the symlinks will be re-created!

Continue reading...

Tags: ,

Ubuntu: ethtool permanent 1000baseTX full-duplex

gimpe » 01 August 2009 » In bash, linux, network » No Comments

vi /etc/init.d/1000Mbs
#!/bin/sh

ETHTOOL="/usr/sbin/ethtool"
DEV="eth0"

case "$1" in
    start)
        echo -n "Setting eth0 speed 1000 full-duplex...";
        $ETHTOOL -s $DEV speed 1000 duplex full autoneg on;
        echo " done."
        ;;
    stop)
        ;;
esac

exit 0
update-rc.d 1000Mbs defaults

SOURCE: http://www.cyberciti.biz/tips/howto-linux-add-ethtool-duplex-settings-permanent.html

Continue reading...

Tags: , ,

Windows Backup using rsync and DeltaCopy

gimpe » 18 February 2009 » In FreeNAS, bash » No Comments

newrsynclogo

Use DeltaCopy (as rsync server) on the Windows box:

http://www.aboutmyip.com/AboutMyXApp/DeltaCopy.jsp

You’ll need to open port TCT/873 in your windows firewall.

Note: To fix the accentuated characters issue in the filenames, you can replace the “Cygwin1.dll” in the DeltaCopy directory by a UTF-8 compliant Cygwin dll (http://www.okisoft.co.jp/esc/utf8-cygwin/). Then restart the service or reboot.

And here’s my bash script running on my Linux box (all the files are in a “backup-tools” directory):

#!/bin/bash

passwdfile=~ACCOUNT/backup-tools/passwd
excludefile=~ACCOUNT/backup-tools/exclude
options="--delete-after --recursive --exclude-from=$excludefile --human-readable --stats --times"

# This gives a  bored user something to watch
if [ "$1" = "--progress" ];
then
    options="$options --progress"
fi

echo "--starting--"

rsync OPTIONNALUSERNAME@SEVERADDRESS::DELTACOPYMODULENAME /WHERETOBACKUP --password-file=$passwdfile $options

echo "--done--"

Then I run it daily in the crontab (command “crontab -e”):

@daily ~ACCOUNT/backup-tools/rsync.sh | mail ACCOUNT -s "daily rsync result"

Ref: http://dailycupoftech.com/windows-backup-with-rsync-and-freenas/

Continue reading...

Tags: