Bash script to sync KeepassX database

I created a my first little bash script to sync my Keepass(X) (Keepass on Windows boxes and KeepassX on Linux boxes) over a secure (SSL + Login) webdav enabled site.
#!/bin/bash
host=https://www.some_dav_enabled_website.com/db.kdb
user=foo
pass=bar
fpath=/somefolder/db.kdb
function update {
echo "Deleting old KeepassX database..."
rm $fpath
echo "Downloading new KeepassX database..."
curl -sku $user:$pass $host -o $fpath
echo "Starting KeepassX..."
keepassx $fpath &
function sync {
echo "Uploading the KeepassX database to server..."
curl -sku $user:$pass -X PUT -T $fpath $host &> /dev/null
echo "Database updated!"
while getopts "us" optname
do
case "$optname" in
"u")
update
"s")
sync
echo "Usage: -u Update to the latest KeepassX database."
echo " -s Sync the (un)modified KeepassX database."
esac
done
Enjoy !
Last edited by SiB (2008-07-31 23:58:59)

Hi Sybrand Bakker,
I tried streams for the replication purpose as per your suggesion, till Iam unable make it work , i dont find a step by step document which will make it possible without error.
One more thing , i need the streams work without Database link, ie., source database is not connected directly to destination database. I need to create streams and transfer the stream as a file through FTP.I need to download stream file in remote location and then apply the streams to destination database and after this source and destination database should be same in data and schema.
Please suggest me a solution to go abt this scenario. We are in critical stage to make it happen...
thanking you in advance
with regards
vivek
Message was edited by:
Vivekanandh

Similar Messages

  • Anacron: bash script not working

    hi together,
    i don't know why my script isn't started by anacron - so i hope someone can help me.
    bash script "update" (shortened):
    #!/bin/bash
    function update_notifier
    yaourt -Sy > /dev/null 2>&1 && sudo -u "user" notify-send -u critical "notebook" "updates: $(yaourt -Qua | wc -l)"
    case $1 in
    "notifier") update_notifier;;
    esac
    /etc/anacrontab:
    SHELL=/bin/bash
    PATH=/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl:
    MAILTO=""
    RANDOM_DELAY=30
    START_HOURS_RANGE=5-22
    @daily 15 cron.daily nice run-parts /etc/cron.daily
    @weekly 15 cron.weekly nice run-parts /etc/cron.weekly
    @monthly 15 cron.monthly nice run-parts /etc/cron.monthly
    @daily 15 update.notifier /full/path/to/script/update notifier > /dev/null 2>&1
    If i start my script with
    update notifier
    everything is working.
    If i force anacron to run with
    sudo anacron -f -n
    everything is working.
    journalctl:
    anacron[2093]: Job `update.notifier' started
    anacron[2093]: Job `update.notifier' terminated
    PATH in anacrontab and bash are identically.
    sudo -u "user" notify-send ...
    gives notify-send permission to display.
    So what am I missing? Thanks for any hint!

    i've read it and understand that yaourt -Sy <package> is indeed a bad idea, but i just want to sync my database and then check for packages to upgrade. Could you give a good example with yaourt/pacman please?
    so my function update_notifier should better be
    sudo -u "user" notify-send -u critical "notebook" "updates: $(checkupdates | wc -l)"
    right?
    what is the better solution in /etc/anacrontab
    @daily 15 update.notifier DISPLAY=:0 /full/path/update notifier
    or something like this
    @daily 15 update.notifier source /path/to/.bash_profile /full/path/update notifier
    or this
    @daily 15 update.notifier /bin/bash /full/path/update notifier
    Last edited by s0l!d (2015-03-16 21:57:06)

  • What do you think of my Bash Script? What about the error checking?

    Well what do you think of this Bash script
    It works
    I gave it some problems (i.e. unpluged the ethernet, messed up the URL's, uninstaled some programs...) to see if would report errors and stop or just keep going... But it did
    I just kind of thought up a way to do some error checking with the commands that I know.....
    What is a better way to do error checking?
    What do you think I should add/Do to this script?
    #!/bin/bash
    # Shell script to make a USB Tumb Drive for Flashing BIOS on a Lenovo Ideapad Y510.
    # This script needs to be owned and run as ROOT with the "sudo command"
    # i.e. sudo usbbiosflasher
    # If you have anyideas send me a PM on ubuntufourms.org my user name is HunterThomson
    # Name/Rename this script usbbiosflasher and save it to the ~/home directory.
    # Then run the command- chown root:root usbbiosflasher
    # Then run the command- chmod 755 usbbiosflasher
    # Then copy the script to the directory /usr/bin.
    # Run this comand to do that- sudo cp ~/usbbiosflasher /usr/bin
    # You also must have the program "mbr" installed
    # You can install the mbr program by running this comand in the shell on Ubuntu
    # sudo apt-get install mbr
    # In Arch Linux you have to get it from Aur
    # First you will need to know a few things...
    # You will also need to know the Mount Point i.e. /media/disk and the /dev path i.e. /dev/sdb1.
    # You can find these by using the df -T comand.
    # Run df -T in the shell. Then plug in the USB Thumb Drive and run the df -T comand agin.
    # The new listing is the USB Thumb Dirve.
    # Also check to make sure the File System tipe is vFAT or FAT16 or FAT32.
    # If it is not use gparted to format it to FAT32.
    # I am farly certen that all USB Thumb drives come formated with FAT file system out of the BOX.
    # You may want to fromat it anyway just to make sure.
    echo "Interactive Shell Script to Make a USB Thumb Drive \for Flashing BIOS On a Lenovo Ideapad Y510"
    echo ""
    echo "You will need to have the program mbr installed"
    echo "If you are on Ubuntu Linux you can retreve it form the repositories"
    echo "If you are on Arch Linux you will need to get it from the Aur repository"
    echo "Open anuther shell and \do that now..."
    echo ""
    verify="n"
    while [ "$verify" != y ]
    do
    printf "Do you have mbr installed... yes or no?"
    read AN1
    echo ""
    printf "You answered... $AN1 I have installed mbr. Is this correct... y or n?"
    read verify
    done
    echo ""
    if [ "$AN1" == "no" ]
    then
    echo "Install mbr now. Then run this script agin"
    exit
    else
    echo "contunuing script"
    fi
    echo ""
    # The next comand will make a directory to put needed files into. Note this file and everything init will be owned by root.
    mkdir ~/usbbiosfiles && check1="yes"
    if [ "$check1" = "yes" ]
    then
    echo "Made directory usbbiosfiles... OK"
    else
    echo "Could not \make directory usbbiosfiles"
    echo "look above \for \info"
    echo "Fix the problem and run this scrip agin"
    exit
    fi
    # The next two comands will get the FreeDOS file and the .ROM file.
    cd ~/usbbiosfiles && checka="yes"
    if [ "$checka" = "yes" ]
    then
    echo "Changing to the usbbiosfiles directory... OK"
    else
    echo "Could not Change to the usbbiosfiles directory"
    echo "look above \for \info"
    echo "Fix the problem and run this scrip agin"
    echo ""
    echo "removeing directory usbbiosfiles..."
    echo ""
    rm -r ~/usbbiosfiles
    exit
    fi
    wget "http://www.fdos.org/bootdisks/autogen/FDOEM.144.gz" && check2="yes"
    if [ "$check2" = "yes" ]
    then
    echo "Download of FreeDOS... OK"
    else
    echo "Could not Download FreeDOS"
    echo "look above \for \info"
    echo "Fix the problem and run this scrip agin"
    echo ""
    echo "removeing directory usbbiosfiles..."
    echo ""
    rm -r ~/usbbiosfiles
    exit
    fi
    wget "http://ubuntuforums.org/attachment.php?attachmentid=78460&d=1216648756" && check3="yes"
    if [ "$check3" = "yes" ]
    then
    echo "Download of the BIOS.ROM \file... OK"
    else
    echo "Could not Downlad the BIOS.ROM \file"
    echo "look above \for \info"
    echo "Fix the problem and run this scrip agin"
    echo ""
    echo "removeing directory usbbiosfiles..."
    echo ""
    rm -r ~/usbbiosfiles
    exit
    fi
    # The next comand will name the .ROM file to the right name.
    mv ~/usbbiosfiles/attachment.php?attachmentid=78460\&d=1216648756 ~/usbbiosfiles/06CN29WW.bios.update.tar.bz2 && check4="yes"
    if [ "$check4" = "yes" ]
    then
    echo "Renameing of the BIOS.ROM \file... OK"
    else
    echo "Could not rename the BIOS.ROM \file"
    echo "look above \for \info"
    echo "Fix the problem and run this scrip agin"
    echo ""
    echo "removeing directory usbbiosfiles..."
    echo ""
    rm -r ~/usbbiosfiles
    exit
    fi
    echo ""
    # The next two comands set the variables. DEVX for the path i.e. /dev/xxx and MOUNTX for the mount point i.e. /media/xxx
    verify="n"
    while [ "$verify" != y ]
    do
    echo "You will need to know the Mount Point and the dev Path. You will also need to \make sure the File System \type is vFAT, FAT16 or FAT32."
    echo ""
    echo "With the USB Thumb Drive unpluged, Open another shell and run the comand df -T Then plug \in the USB Thumb Drive and run the comand df -T one \more time. The new device listed is the USB Thumb Drive. Note the Mount Point and The dev Path and the File system Type i.e. vFAT... If the File System \type is not vFAT, FAT16 or FAT32 you will need to fromat it with gparted. You may want to format the USB Thumb Drive anyway just to \make sure. In any \case delete all files and directorys on the USB drive before you go any ferther with this program."
    echo ""
    printf "Enter the dev path the USB Thumb Drive is at?"
    read DEVX
    echo ""
    echo "Are you sure $DEVX is the dev path of the USB Thumb Drive... y or n?"
    read verify
    done
    echo ""
    verify="n"
    while [ "$verify" != y ]
    do
    printf "What is the Mount Point of the USB Thumb Drive?"
    read MOUNTX
    echo ""
    echo "Are you sure $MOUNTX is the Mount Point of the USB Drive... y or n?"
    read verify
    done
    echo ""
    install-mbr --enable A1 --partition 1 --force --timeout 0 $DEVX && check5="yes"
    if [ "$check5" = "yes" ]
    then
    echo "Installing MBR on USB Thumb Dirve... OK"
    else
    echo "Could not install MBR on USB Thumb Drive"
    echo "look above \for \info"
    echo "Fix the problem and run this scrip agin"
    echo ""
    echo "removeing directory usbbiosfiles..."
    echo ""
    rm -r ~/usbbiosfiles
    exit
    fi
    tar xjf ~/usbbiosfiles/*.tar.bz2 && check7="yes"
    if [ "$check7" = "yes" ]
    then
    echo "Unpacking BIOS.ROM file... OK"
    else
    echo "Could not unpack BIOS.ROM file"
    echo "look above \for \info"
    echo ""
    echo "Reformat the USB Stick to FAT32 with gparted"
    echo "Fix the problem and run this scrip agin"
    echo ""
    echo "removeing directory usbbiosfiles..."
    echo ""
    rm -r ~/usbbiosfiles
    exit
    fi
    gunzip ~/usbbiosfiles/FDOEM.144.gz && check8="yes"
    if [ "$check8" = "yes" ]
    then
    echo "Unpacking FreeDOS files... OK"
    else
    echo "Could not unpack FreeDOS files"
    echo "look above \for \info"
    echo ""
    echo "Reformat the USB Stick to FAT32 with gparted"
    echo "Fix the problem and run this scrip agin"
    echo ""
    echo "removeing directory usbbiosfiles..."
    echo ""
    rm -r ~/usbbiosfiles
    exit
    fi
    mkdir ~/usbbiosfiles/fdoem144 && check9="yes"
    if [ "$check9" = "yes" ]
    then
    echo "Made directory fdoem144 in direcoty usbbiosfiles... OK"
    echo ""
    echo "Going to \sleep \for 5secs"
    else
    echo "Could not make directory fdoem144 in usbbiosfiles directory"
    echo "look above \for \info"
    echo ""
    echo "Reformat the USB Stick to FAT32 with gparted"
    echo "Fix the problem and run this scrip agin"
    echo ""
    echo "removeing directory usbbiosfiles..."
    echo ""
    rm -r ~/usbbiosfiles
    exit
    fi
    modprobe loop && sleep 5 && check0="yes"
    if [ "$check0" = "yes" ]
    then
    echo "Modprobeing loop... OK"
    else
    echo "Could not \modprobe loop"
    echo "look above \for \info"
    echo ""
    echo "Reformat the USB Stick to FAT32 with gparted"
    echo "Fix the problem and run this scrip agin"
    echo ""
    echo "removeing directory usbbiosfiles..."
    echo ""
    rm -r ~/usbbiosfiles
    exit
    fi
    mount -o loop ~/usbbiosfiles/FDOEM.144 ~/usbbiosfiles/fdoem144 && check10="yes"
    if [ "$check10" = "yes" ]
    then
    echo "Mounting FreeDOS on the fdoem144 directory... OK"
    else
    echo "Could not \mount FreeDOS on the fdoem144 directory"
    echo "look above \for \info"
    echo ""
    echo "Reformat the USB Stick to FAT32 with gparted"
    echo "Fix the problem and run this scrip agin"
    echo ""
    echo "removeing directory usbbiosfiles..."
    echo ""
    rm -r ~/usbbiosfiles
    exit
    fi
    cp ~/usbbiosfiles/fdoem144/* $MOUNTX && check11="yes"
    if [ "$check11" = "yes" ]
    then
    echo "Copying FreeDOS files to $MOUNTX... OK"
    else
    echo "Could not copy FreeDOS files to $MOUNTX"
    echo "look above \for \info"
    echo ""
    echo "Reformat the USB Stick to FAT32 with gparted"
    echo "Fix the problem and run this scrip agin"
    echo ""
    echo "removeing directory usbbiosfiles..."
    echo ""
    rm -r ~/usbbiosfiles
    exit
    fi
    cp ~/usbbiosfiles/*.ROM $MOUNTX && check12="yes"
    if [ "$check12" = "yes" ]
    then
    echo "Copying BIOS.ROM files to $MOUNTX... OK"
    else
    echo "Could not copy BIOS.ROM files to $MOUNTX"
    echo "look above \for \info"
    echo ""
    echo "Reformat the USB Stick to FAT32 with gparted"
    echo "Fix the problem and run this scrip agin"
    echo ""
    echo "removeing directory usbbiosfiles..."
    echo ""
    rm -r ~/usbbiosfiles
    exit
    fi
    sync && check13="yes"
    if [ "$check13" = "yes" ]
    then
    echo "Runing the syncing command... OK"
    else
    echo "Could not run the syncing command"
    echo "look above \for \info"
    echo ""
    echo "Reformat the USB Stick to FAT32 with gparted"
    echo "Fix the problem and run this scrip agin"
    echo ""
    echo "removeing directory usbbiosfiles..."
    echo ""
    rm -r ~/usbbiosfiles
    exit
    fi
    umount ~/usbbiosfiles/fdoem144 && check14="yes"
    if [ "$check14" = "yes" ]
    then
    echo "Unmounting of FreeDOS... OK"
    else
    echo "Could not unmount FreeDOS"
    echo "Look above for errors or problems reported and fix the problem"
    echo ""
    echo "removeing directory usbbiosfiles..."
    echo ""
    echo "Reformat the USB Stick to FAT32 with gparted"
    echo "Fix the problem and run this script agin"
    rm -r ~/usbbiosfiles
    exit
    fi
    verify="n"
    while [ "$verify" != y ]
    do
    printf "Do you see any errors... yes or no?"
    read AN2
    echo ""
    printf "You answered... $AN2 to errors. Is this correct... y or n?"
    read verify
    done
    echo ""
    if [ "$AN2" == "yes" ]
    then
    echo "User Repoted... Error"
    echo "Look above for errors or problems reported and fix the problem"
    echo ""
    echo "removeing directory usbbiosfiles..."
    echo ""
    echo "Reformat the USB Stick to FAT32 with gparted"
    echo "Fix the problem and run this script agin"
    rm -r ~/usbbiosfiles
    exit
    else
    echo "Success"
    echo "I did a lot of error checking too and didnt find anything"
    echo ""
    echo "Go get a pen and paper to write down these instructions"
    printf "Then hit the Enter to continue"
    read WAIT
    echo ""
    echo "Now leave the USB Thumb Drive pluged into your computer and Reboot. When the Lenovo Logo POST screen appears hit F2 to enter the CMOS setup utility. Go over to BOOT tab and go down to HardDrive \(Not Boot Order) \then \select the USB Thumb Drive as the 1st hard drve. Then F10 and yes to save changes. Your compter will reboot agin. Then when the Lenovo Logo POST Screen appers on reboot hit F4 to enter the BIOS FLASHING program. The USB Thumb Drive will be seen as the C drive \in the list on the Left, Select it. Then \select the .ROM \file \in the list on the Right and start the BIOS FLASH. \(NOTE Your hart may stop beating... This is normal) Pray to any God you know of and your computer should restart just like normal. Hit F2 and the BIOS will now stay it is 06CN29WW. You will need to \set the boot order to the way you like it and other things \if you need to because they have been changed to the default."
    fi
    echo ""
    echo "End of script"
    Last edited by hunterthomson (2008-08-10 11:17:47)

    Personally.....  (this is just how I would have written it - if it works, then it's good enough for me though )
    I would change this whole block:
    verify="n"
    while [ "$verify" != y ]
    do
    printf "Do you have mbr installed... yes or no?"
    read AN1
    echo ""
    printf "You answered... $AN1 I have installed mbr. Is this correct... y or n?"
    read verify
    done
    echo ""
    if [ "$AN1" == "no" ]
    then
    echo "Install mbr now. Then run this script agin"
    exit
    else
    echo "contunuing script"
    fi
    To this much shorter code:
    MBR='/usr/bin/install-mbr' # Or where ever you expect it to be
    if [ ! -x $MBR ] ; then
    echo "mbr doesn't appear to be installed."
    echo "If it is installed, check it's location, make sure it's executable and then make sure the MBR variable in this script is correct"
    exit 1
    fi
    I wouldn't have used the checkXX variables for each stage:
    mkdir ~/usbbiosfiles
    if [ $? != 0 ] ; then
    #failed
    echo "Could not \make directory usbbiosfiles"
    echo "look above \for \info"
    echo "Fix the problem and run this scrip agin"
    exit 1
    else
    echo "Made directory usbbiosfiles... OK"
    fi
    There is an issue with the way you do your verifications - the user can never get out unless they answer 'y' or hit CTRL+C. Something like this gives them options:
    verify="n"
    while [ "$verify" != "y" && "$verify" != "n" ]; do
    echo "You need to answer 'y'es or 'n'o"
    read verify
    echo $verify | tr "[:upper:]" "[:lower:]" # This converts the answer to lowercase so replies entered in upper case will still work
    done
    if [ $verify != 'y' ] ; then
    exit 1
    fi
    One last thing I try to do in scripts... Declare all your binaries as variables at the start of the program, then execute the binary program by using the variable. For example:
    # Binaries
    TAR='/bin/tar'
    CP='/bin/cp'
    CHMOD='/bin/chmod'
    # Execute tar and chmod the created file
    $TAR cvzf /tmp/tarfile.tar.gz /etc/*.conf
    $CHMOD 400 /etc/*.conf
    This way, it's easy to change the path in future without having to hunt through the script if the paths change, and it also ensures you're calling the programs using the full paths to make sure you're not executing some strange variant or alias that someone has setup. If I use `chmod` 30 times in a script, and the path changes in the future or on a different system (`chmod` is a bad example cause it's highly unlikely to change, but you know what I mean), then all you need to do is update the variable at the start of the script, and it all works again without having to script-hunt and change it 30 times.

  • A bash script to backup system only with modified files

    Hi,
    I've made a simple bash script to exam which files are modified and needed to be backed up.
    It will use:
    1. the hash in Pacman's database (/var/lib/pacman/local/<pkg_ver>/files
    2. if no hash in the database, calculate it by our self from cache (/var/cache/pacman/pkg/<pkg_ver>.pkg.tar.gz
    3. if no cache found, compare build date and last modified date
    4. otherwise, this file better be backed up.
    Currently it will only print which files are needed to be backed up, but no backup actually happens. (dry run)
    And it is only in early development stage, please be careful.
    USAGE:
    <the script name> <where to backup files, a directory> <the files, or directories, separated by space, that are going to be examined>...
    Here is the code.
    #!/bin/bash
    # usage:
    # $1: file to backup
    function do_backup() {
    echo
    function smart_bak() {
    pkg=$(pacman -Qo "$1" 2>/dev/null)
    if [ 1 -eq $? ] ; then
    # No package owns $1 (locally created)
    if [ "$1" != "${1%.pacsave}" ] ; then
    echo "skip $1 (left by removed package)"
    else
    echo "backup $1 (local file)"
    fi
    else
    pkg=${pkg#$1 is owned by }
    # evaluate
    # by hash
    cur=$(md5sum $1)
    cur=${cur%% *}
    pkg_ver=${pkg/ /-}
    org=$(grep "^${1:1}" "/var/lib/pacman/local/$pkg_ver/files")
    org_hash=${org##* }
    if [ "$org" != "$org_hash" ] ; then
    # the org hash is in Pacman's database
    if [ "$org_hash" = "$cur" ] ; then
    echo "skip $1 (original config)"
    else
    echo "backup $1 (modified config)"
    fi
    else
    # no hash
    # find out hash myself?
    ARCH=$(uname -m)
    if [ -r "/var/cache/pacman/pkg/$pkg_ver-$ARCH.pkg.tar.gz" ] ; then
    org=$(tar -Oxzf "/var/cache/pacman/pkg/$pkg_ver-$ARCH.pkg.tar.gz" "${1:1}" | md5sum -)
    org_hash=${org%% *}
    if [ "$cur" = "$org_hash" ] ; then
    echo "skip $1 (original)"
    else
    echo "backup $1 (modified)"
    fi
    else
    # no cache, may be a AUR package
    # fall back to built date?
    date=$(pacman -Qi ${pkg% *} | grep "^Build Date")
    date=${date#*: }
    date=$(date -d "$date" +%s)
    mod=$(ls -l $1)
    mod=${mod% $1}
    mod=${mod#* * * * * }
    mod=$(date -d "$mod" +%s)
    tmp1=$(expr $mod "+" 60)
    tmp2=$(expr $mod "-" 60)
    if [ "$date" -le "$tmp1" -a "$date" -ge "$tmp2" ] ; then
    echo "skip $1 (the same date)"
    else
    echo "backup $1 (unknown)"
    fi
    fi
    fi
    fi
    function smart_bak_dir() {
    for i in $(ls -A "$1") ; do
    tmp="${1%/}/$i"
    if [ -f "$tmp" ] ; then
    smart_bak "$tmp"
    elif [ -d "$tmp" ] ; then
    smart_bak_dir "$tmp"
    else
    echo "skip $tmp (not a regular file nor a directory)"
    fi
    done
    # usage:
    # $1: the directory to store this backup
    # $2: directory to evalualte for backup
    # function main()
    # init
    target="$1"
    shift
    # check
    if [ ! -d "$target" -o ! -x "$target" -o ! -w "$target" ] ; then
    exit 4
    fi
    for i in $* ; do
    if [ -f "$i" ] ; then
    smart_bak "$i"
    elif [ -d "$i" ] ; then
    smart_bak_dir "$i"
    else
    echo "skip $i (unknown argument)"
    fi
    done
    Good luck,
    bsdson
    Last edited by bsdson.tw (2008-12-30 07:53:05)

    Thanks for this script. Nice work.
    Can we traverse the pacman.log backwards up and rollback each operation (including "installed" in this). Something like:
    history=$(tail -n +$(grep -m 1 -n "$1" "$LOG" | cut -d ":" -f 1) "$LOG" | tac | grep -E "(upgraded|installed)" | cut -d " " -f 3-)
    Last edited by g33k (2008-11-04 15:08:07)

  • My first bash script - update mirrors and then update your system.

    Like the title says, this is my first attempt at a bash script.
    I wrote it to make it a tiny bit easier for my wife to keep her system up to date without needing to remember the terminal commands.  She runs it via an entry in her openbox menu.
    It calls on reflector to check all available mirrors for the most up to date and then use rankmirrors to find the fastest 5 and write them to /etc/pacmand.d/mirrorlist
    Finally, it syncs and upgrades via the command pacman -Syyu
    #!/bin/bash
    # runs reflector to optimize mirrors
    echo "I'm afraid I can't do that Dave"
    sudo reflector -l 5 -r -o /etc/pacman.d/mirrorlist
    echo " I hope you trust me..."
    echo " "
    sleep 2s
    # updates system
    sudo pacman -Syyu

    I've scavenged some code to take care of the root thing, but why rebase vs pacman?  After reading up on rebase a bit, I'm not quite sure how to use it to complete the upgrade once it's updated everything.

  • Bash script - sqllite insert problem

    So, I'm making a bash script that inserts a config file into a database, but I can't get it to work.
    This is my best attempt so far:
    name="bashrc"
    location="/home/user/.bashrc"
    content=`cat "$location"`
    sqlite3 testdb "insert into dbase values ('`echo $name`','`echo "$location"`','`echo "$content"`')"
    the table is
    create table dbase(name text, location text, data text)
    I had a hard time trying to figure out how I'd be able to get $variables to work (because of the quotes) and this echo style seems to work, but there seems to be no way to insert the config file into the database.
    plaintext files seem to work no problem, but when I'm trying to insert some config file, it spits out errors. (It seems like it's trying to execute the file somehow?)
    Last edited by initbox (2009-08-29 15:28:49)

    initbox wrote:I was thinking the single quotes were stopping bash from replacing $variables with the content, hence the echoes.
    your single quotes are inside a double quote, so to bash they're just another character in the string.
    I'm still getting an SQL syntax error, so bash is no longer getting in the way, but this thing is a true nightmare. What next? This turned out to be way harder than I expected, I'm just doing this as a "fun" learning experiment.
    Your error is probably because I was escaping the quotes for bash, and I should have been escaping them for sqlite. In sqlite, escaping a quote is done by doubling it, so ' is escaped to '' (that's two apostrephes side by side, not a double quote. Compare '' and ").
    This untested sed command might work:
    content = $(cat $location | sed "s/\'/\'\'/g")
    The \'s are escaping the quote from bash, what its really doing is replacing ' with ''.
    Dusty

  • How to run bash script using Calendar

    Hi folks.
    How can I run a bash script using Calendar?  I thought I had to park it in an AppleScript script which I could call, but that isn't really working.
    Any suggestions appreciated.
    Cheers

    Hi there.  Thanks for the reply.
    Some notes for the replies:
    - The shell script has no environment issues.  It's a straight mysqldump for a single database.
    - The AppleScript has the do shell script "path/to/script.sh" user name "root" password "wobblyhead" with administrator privileges
    - Calendar application can only recognize the .scptd and .scpt files, and not .app files.  Upon choosing my original .scpt file with the do shell script instruction, it just opens the file in AppleScript Editor. 
    So the file gets called, but for some reason, it just opens the file and won't run the file.  No options for choosing a format where it's actually run. 
    Not sure how to go about this. 
    Cheers

  • Syncing two database via archivelogs

    Hello Gurus of the Oracle World.
    I have two database I want to keep in sync. both databases are 7.3.4 database. Yeah I know they are old and out of date. But this is my world and it is very old . My question is am using sqlbacktrack as a backup and recovery tool. I am able to backup my primary database and restore it to a different location. Now my problems is keeping them in-sync every 1 to 2 hours. Is there a script I can use to apply the archive logs via some type of cronjob? So that when I copy the archive log files over to the secondary database I can apply them automatically with no intervention from me or any users.
    Your help is greatly appreciated.
    Thanks.

    I don't know exactly how sqlbacktrack works. I also don't recall a lot about 7.3.4, so take this with a grain of salt...
    When you recover the database on to the other machine, do you know whether the recovery process does anything like resetting the archive log sequence? I would expect that your tool has some sort of option to prevent this, at least.
    Once you have the standby database, you should be able to put the database in manual recovery mode and have a script that copies archived log files from the primary to the standby and applies them to the standby. The standby database cannot be open for this-- user's wouldn't be able to access the data unless you stopped the recovery process and opened the database. The database would also have to be opened read-only.
    Niall Litchfield's presentation "You Probably Don't Need Data Guard" would be a good place to start. The presentation and scripts are linked from his site
    http://www.niall.litchfield.dial.pipex.com/
    Justin
    Distributed Database Consulting, Inc.
    http://www.ddbcinc.com/askDDBC

  • Sending email using bash script

    Hello:
    I am working on writing a bash script to notify one or more users by email of certain events. Run from the Terminal command line, and having the script "echo" text of (what would be) a form letter with in-line variable expansion (i.e., ${VARIABLE}), all seems to work as anticipated. Eventually, I want cron to launch this shell script, and send an email to an "on-subnet" user (I have postfix enabled on my Mac, and there are multiple local user accounts).
    I found some stuff on the web about sending mail from bash scripts, and so I made a small little test script, that reads like this:
    #!/bin/bash
    VARIABLE[1]="The 12,345 quick brown foxes "
    VARIABLE[2]="jumped over the 67,890 lazy dogs."
    mail -s "a test email" jv << EOF
    This is a test:
    ${VARIABLE[1]}
    ${VARIABLE[2]}
    This is the last line of the test message.
    EOF
    echo "script completed"
    It worked... almost... It sent a local email to my postfix mail account that read like this:
    This is a test:
    The 12,345 quick brown foxes
    jumped over the 67,890 lazy dogs.
    This is the last line of the test message.
    EOF
    echo "script completed"
    So, I have two questions. First, the easy one (I hope):
    How do I delimit the end of the text, that I want to be the message body of the email, from portions of the script that follow said email text?
    Next question is a little more involved. You know how, in Mail.app, if you go to Mail Preferences>Accounts>Account Information, you can put multiple email addresses, comma-delimited, in the "Email Address" field? So, if a person entered "[email protected], [email protected], [email protected]" in this field, then, even though (s)he may be at home, and using their home ISP's mail server, (s)he could send an email apparently from either their home, work, or school email address. Of course, the mail headers clearly would show it came from and through their home machine and home ISP, but it would be displayed in the recipient's Mail client viewer as having come from one of [email protected], [email protected], or [email protected].
    I'd like to do something similar here, whereby the email (that is being sent to one or more local users' postfix account on my computer) would apparently be sent from "watchdog@localhost" rather than from "jv@localhost" like it seems to do by default. Whatever account the script is run from (or presumbably, whose cron tab is launching the script) is what the "From" address is set to.
    I'd rather not create an additional mail account, because I am using Mac OS X built-in accounts for the postfix mailboxes (I don't want to have to maintain a plaintext username:password file in postfix, and I don't want to create an additional user account on the computer).
    So, is there a way to specify an alternate "From" username when invoking the mail -s ${SUBJECT} ${RECIPIENT} command in a bash script? Or is there a different, alternate mail command that will let me do so? (please include a description of syntax and how I'd package the above message text for the alternate method).
    Thanks in advance, all!

    Hi j.v.,
    The > after EOF is just a typo (or may be added by the Discussion ?) and you must delete it; other > are prompts from the interactive shell. Andy's post shows an interactive use of shell, not a shell script (note the shell prompt % in front of the commands). A typical use of here document may look like
    command <<ENDOFDATA
    ENDOFDATA
    There must be no spaces before and after ENDOFDATA. The word ENDOFDATA can be EOF or any other string which is guaranteed not to appear in the text (the .... in the example above).
    You can modify the From: header by using sendmail command (postfix has it as a compatibility interface):
    /usr/sbin/sendmail -t <<EndOfMessage
    Subject: test mail
    To: jv
    From: watchdog
    This is a test:
    ${VARIABLE[1]}
    ${VARIABLE[2]}
    This is the last line of the test message.
    EndOfMessage
    There must be a blank line between the headers and the mail body.
    I assume that you send these mails only to users on your local Mac. Please do not send mails to remote users by using the sendmail command unless you know what you are doing completely.
    PowerMac G4   Mac OS X (10.4.5)  

  • [SOLVED] problem with spaces and ls command in bash script

    I am going mad with a bash script I am trying to finish. The ls command is driving me mad with spaces in path names. This is the portion of my script that is giving me trouble:
    HOMEDIR="/home/panos/Web Site"
    for file in $(find "$HOMEDIR" -type f)
    do
    if [ "$(dateDiff -d $(ls -lh "$file" | awk '{ print $6 }') "$(date +%F)")" -gt 30 ];
    then echo -e "File $file is $(dateDiff -d $(ls -lh "$file" | awk '{ print $6 }') "$(date +%F)") old\r" >> /home/panos/scripts/temp;
    fi
    done
    The dateDiff() function is defined earlier and the script works fine when I change the HOMEDIR variable to a path where there are no spaces in directory and file names. I have isolated the problem to the ls command, so a simpler code sample that also doesn't work correctly with path names with spaces is this:
    #!/bin/bash
    HOMEDIR="/home/panos/test dir"
    for file in $(find "$HOMEDIR" -type f)
    do
    ls -lh "$file"
    done
    TIA
    Last edited by panosk (2009-11-08 21:55:31)

    oops, brain fart. *flushes with embarrassment*
    -- Edit --
    BTW, for this kind of thing, I usually do something like:
    find "$HOMEDIR" -type f | while read file ; do something with "$file" ; done
    Or put those in an array:
    IFS=$'\n' ; files=($(find "$HOMEDIR" -type f)) ; unset IFS
    for file in "${files[@]}" ; do something with "$file" ; done
    The later method is useful when elements of "${files[@]}" will be used multiple times across the script.
    Last edited by lolilolicon (2009-11-09 08:13:07)

  • Can't get conky-cli and bash scripts to both display in dwm statusbar!

    I'm trying to configure my dwm status bar to display some simple information using conky-cli and bash scripts. At first I tried just letting conky run the bash scripts (for network and volume state), but this increased my cpu usage by about 5%, which is significant considering I normally have 1-3% usage when idle. Also, I wanted to keep conky because it makes the display of certain information easy, such as cpu & RAM usage.
    The problem is I'm having trouble getting both to display side by side. Here are the relevant parts of my .xinitrc:
    network(){
    iwconfig wlan0 2>&1 | grep -q no\ wireless\ extensions\. && {
    echo wired
    exit 0
    essid=`iwconfig wlan0 | awk -F '"' '/ESSID/ {print $2}'`
    stngth=`iwconfig wlan0 | awk -F '=' '/Quality/ {print $2}' | cut -d '/' -f 1`
    bars=`expr $stngth / 10`
    case $bars in
    0) bar='[-------]' ;;
    1) bar='[#------]' ;;
    2) bar='[##-----]' ;;
    3) bar='[###----]' ;;
    4) bar='[####---]' ;;
    5) bar='[#####--]' ;;
    6) bar='[######-]' ;;
    7) bar='[#######]' ;;
    *) bar='[--!!!--]' ;;
    esac
    echo $essid$bar
    exit 0
    volume(){
    vol=$(amixer get Master | awk -F'[]%[]' '/%/ {if ($7 == "off") { print "MM" } else { print $2 }}' | head -n 1)
    echo Vol: $vol%
    exit 0
    conky | while true; read line; do xsetroot -name "`$line` `volume` `network` `date '+%a %m-%d-%Y %I:%M%p'`"; done &
    exec dwm
    (let me know if it would help to post any other files)
    For some reason when I run this I only get the network/volume scripts and date running, updating every second (I think). The conky line just doesn't show up. I don't know what could be wrong, since I didn't see any error messages.
    An even better solution would be to just have shell scripts to display CPU and MEM usage. I have a dual-core cpu, cpu0 and cpu1. I'd like to see both percentages if possible, or at least a percentage that is an accurate average of the two or something. In conky-cli I have something that shows:
    cpu0/1: xx% xx%
    Also, seeing RAM usage would help a lot. In conky it shows:
    mem: xx% (xxxMB)
    These are the ways I would like to have bash scripts show them, if possible, but I have zero skill in bash programming. I made this an option in case it's easier/cleaner/less resource hungry than a conky solution. Personally, if they're about the same in these aspects, I would prefer something with conky and the shell scripts because conky is so extensible, yet it's only flaw is executing scripts with minimal resource usage.
    Help?

    Thanks. I was thinking of using load average to save a few characters, but I didn't quite understand the numbers. I'll try that once I get to my Linux box, but could you please explain or post a link to something that explains load average (what's low, high, normal, etc.)?
    EDIT: I found a website that explains loadavg. I now have my dwm status bar displaying it perfectly (yay!). Now I just need to add a few more things like battery status, etc. and I might be done. I'll probably post here if I have more questions, though.
    Thanks for your help!
    Last edited by Allamgir (2009-07-18 14:41:11)

  • /etc/rc.d/network: bash script: how to find out, if there was an error

    hello!
    i want to write a bash script for my wireless lan. for this i need the information, if the network daemon has connected successfully or failed.
    but there is a big problem: starting network success' every time, whether there was an error or not:
    $ /etc/rc.d/network start
    :: Starting network profile: 00wlan_home [BUSY]
    Error for wireless request "Set Mode" (8B06) :
    SET failed on device wlan0 ; No such device.
    [FAIL]
    :: Starting Network [DONE]
    $ ls /var/run/daemons/
    ... network ...
    can someone help me please? how can i realize  that "::Starting Network ..." also fails and the script returns an exit status 1?
    thanks for your help, maybe we can improve the script. but i'm not a geek in bash!
    mfg iggy

    iggy wrote:
    hello!
    i want to write a bash script for my wireless lan. for this i need the information, if the network daemon has connected successfully or failed.
    but there is a big problem: starting network success' every time, whether there was an error or not:
    $ /etc/rc.d/network start
    :: Starting network profile: 00wlan_home [BUSY]
    Error for wireless request "Set Mode" (8B06) :
    SET failed on device wlan0 ; No such device.
    [FAIL]
    :: Starting Network [DONE]
    $ ls /var/run/daemons/
    ... network ...
    can someone help me please? how can i realize  that "::Starting Network ..." also fails and the script returns an exit status 1?
    thanks for your help, maybe we can improve the script. but i'm not a geek in bash!
    mfg iggy
    try using netcfg to start the wireless profile, that should keep you happy until the new network scripts are unleashed... which won't have this problem.
    James

  • Script level upgrade for database 'master' failed because upgrade step 'msdb110_upgrade.sql' encountered error 537, state 3, severity 16

    Hello,
    I've encountered issue during installation of SP1 to SQL Server 2012. After upgrade I'm getting this error in Event Log:
    Script level upgrade for database 'master' failed because upgrade step 'msdb110_upgrade.sql' encountered error 537, state 3, severity 16. This is a serious error condition which might interfere with regular operation and the database will be taken offline.
    If the error happened during upgrade of the 'master' database, it will prevent the entire SQL Server instance from starting. Examine the previous errorlog entries for errors, take the appropriate corrective actions and re-start the database so that the script
    upgrade steps run to completion.
    Can someone point me direction how I can fix it? This is a production server and currently only way to make it working is to use T902 flag in SQL Server startup params. I've found some suggestions to check Data path if it exists but it does so this is not
    the issue here. Any ideas?
    I've found also here
    http://www.sqlservercentral.com/Forums/Topic1377073-1550-1.aspx#bm1378279
    suggestions for similar issue with SQL Server 2008 which that I should do:
    Via ssms:
    From msdb:
    Delete:
    dc_admin role
    Dc_operator role
    Dc_proxy role
    UlitityCMRReader role
    UtilityIMRReader role
    UtilityIMRWriter role
    but for not I didn't tried it yet. This is standalone SQL Server instance.
    Any help really appreciated.
    Regards

    Script returns the same error.
    System databases:
    1    1    760    -1    10    1048578    0    1    master        C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA\master.mdf
    2    0    12768    -1    10    1048642    0    1    mastlog        C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA\mastlog.ldf
    1    1    1024    -1    10    1048578    0    2    tempdev        C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA\tempdb.mdf
    2    0    64    -1    10    1048642    0    2    templog        C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA\templog.ldf
    1    1    288    -1    128    2    0    3    modeldev    C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA\model.mdf
    2    0    4464    -1    10    1048642    0    3    modellog    C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA\modellog.ldf
    1    1    28936    -1    10    1048578    0    4    MSDBData    C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA\MSDBData.mdf
    2    0    3352    268435456    10    1048642    0    4    MSDBLog    C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA\MSDBLog.ldf
    are all in place where path shows.
    Before sending my message I've searched update script for "FROM master.sys.master_files" and I found script which you are showing me. I've made some digging and when I runned:
           SELECT physical_name
           FROM master.sys.master_files
           WHERE (name = N'master')
    it returned also path to one my customers database name which has filename set correctly but it's Logical DB name is master and mastlog. I'm running shared hosting company and I allow my customers to restore their DBs from .bak files but I have no idea why
    this customers logical name is set to master and mastlog. Probably when I change this names update script will work as it should. On the other hand in my opinion there should be some kind of fail safe mechanism for situations like this one.
    EDIT: After changing logical name for DB and log for mentioned DB your script runned fine so probably now when I remove T902 flag and restart my SQL Server update will run correctly. Big thanks for resolving this issue.

  • Using Bash script to edit config file

    This is a really simple question, but given that I'm just learning Bash scripting and having this solved now would be really illustrative for me, I would really thank some help here.
    I'm using uzbl, and running Tor+Polipo. So, as you will see below in the tail of the config file, there is a line to redirect the requests of uzbl through Polipo.
    # === Post-load misc commands ================================================
    sync_spawn_exec @scripts_dir/load_cookies.sh
    sync_spawn_exec @scripts_dir/load_cookies.sh @data_home/uzbl/session-cookies.txt
    # Set the "home" page.
    #set uri = https://duckduckgo.com
    # Local polipo proxy
    set proxy_url = http://127.0.0.1:8123
    # vim: set fdm=syntax:
    What I want to accomplish is to comment in/out that line with a key shortcut on Awesome. I've thought of doing 2 scripts to do so and using 2 differente key shortcuts, but I want to "toggle" the proxy redirection with only 1 shortcut. To do so, I suppose that the script should go something like:
    if
    tool 'set proxy_url = http://127.0.0.1:8123' config_file
    then
    tool '#set proxy_url = http://127.0.0.1:8123' config_file
    else
    if
    tool '#set proxy_url = http://127.0.0.1:8123' config_file
    then
    tool 'set proxy_url = http://127.0.0.1:8123' config_file
    fi
    fi
    I know little about sed, but I think is the tool for this job. The most intriging part to me is to ask sed to print the regular expression when it finds it in the config file, and use that as an input in the conditional statement.
    Well, this is a mess I have done here. Hope there is a simple answer to this.
    Thanks in advance.-

    You can do this with a single sed command:
    sed -i 's/^#set proxy_url/set proxy_url/;
    t end;
    s/^set proxy_url/#set proxy_url/;
    : end' config_file
    This edits the file in-place (-i) and first tries to replace the commented with the uncommented line. If that suceeds, sed jumps to the "end" label. If not, it tries to replace the uncommented with the commented line. Thus you don't have to include any logic about the current state: if the first substitution succeeds, the line was obviously commented, if not, it was uncommented, and the second substitution should succeed.
    Note that my knowledge of sed is very limited. There might be a simpler way to do this.
    EDIT: For the sake of example, here's how to do the same in bash using regular expressions. Note how this script needs to use a temporary file to simulate in-place editing, how it needs to process the file line by line manually, etc. All things that sed does out of the box...
    #!/bin/bash
    tmp=test.conf.tmp
    echo -n "" > "$tmp"
    while read line; do
    if [[ "$line" =~ ^#set\ proxy ]]; then
    echo "${line/\#/}" >> "$tmp"
    elif [[ "$line" =~ ^set\ proxy ]]; then
    echo "#$line" >> "$tmp"
    else
    echo "$line" >> "$tmp"
    fi
    done < test.conf
    mv test.conf.tmp test.conf
    To answer your original question, the line
    if [[ "$line" =~ ^#set\ proxy ]]; then
    reads: if the line begins with a "#", followed by "set proxy", then...
    Last edited by hbekel (2011-03-20 10:40:16)

  • HOW DO I  RUN A UNIX BASH SCRIPT FROM JAVA??

    HI. Here's a tricky little problem i have. There's a unix bash script that has some commands in it, that manipulate a file. It appends a certain string variable to a file called users. The users file is an ordinary text file.
    I know this script to work perfectly, when i invoke it like this directyl from the command line: ./addusers.sh
    or even: bash /downloads/selinux/policy/addusers.sh
    Now, i have a java program, and its meant to just execute that script. It doesnt throw any Exceptions at runtime. But when i look at the users file, and expect it to have an extra line that was the string variable, the file is UNTOUCHED!
    Again, direct command line invocation works, but not from java. Here's what my invocation from java looks like:
    Process p = Runtime.getRunTime().exec("bash downloads/selinux/policy/addusers.sh");
    The strange thing is, i tried a different bash command. I tried:
    Process p = Runtime.getRunTime().exec("mkdir /temporary");
    and this worked!
    so why not the other one??
    I cant figure it out.

    You say:
    bash /downloads/selinux/policy/addusers.sh
    And you say in Java:
    Process p = Runtime.getRunTime().exec("bash
    downloads/selinux/policy/addusers.sh");
    As if a leading / would be missing from the Java
    version...nyix says:>
    ...OK sorry about that. i DO have a / in front of the downloads.... section in the java method. So its:
    Process p = Runtime.getRunTime().
    exec("bash /downloads/selinux/policy/addusers.sh");
    HELP please?

Maybe you are looking for

  • How to do Home Share with 2 different Apple ID's? Spouse and I

    How do I set up the Home Share when there are 2 different Apple ID's? Spouse and I. We each have accounts but are trying to share music. Is this possible? Can I reset my Apple ID and Password?

  • Servlet side problem

    hi there, i have managed to get my mipd program talking 2 a tomcat server, but i have run into the following problem: the servlet has at initiation a buffer called int l = 0; and increment the l value by 1 , this is fine but when i get another phone

  • Style /SMB11/Bl_SF not exist in Production client

    Hi Experts. We found that the Smartform style is not found in Production. But the same is available in Development & Quality. We need to transport the same to Production. How to create the transport for this Style in Development & transport to produc

  • Daylight Savings Time issue with Palm Treo 755p/Missing Sync 6.0.6

    I'm not sure where the fault is, but here's what a user sees here: User has a Palm Treo 755p with the 1.08 software installed. Since DST on March 14th, when he syncs the iCal information to the phone using Missing Sync 6.0.6, the information on the p

  • Arp inspection not working on ASA

    Folks, I configured a transparent firewall on ASA. I have arp inspection enabled, with dynamic mac learning and dynamic arp. I am able to ping through the transparent firewall using 2 routers with the same mac-address. The firewall shows me that it i