Jump to content

Linux shell problems

Hi,

 

i have a simple bash script that runs perfectly when executed directly, but when running it from ruby using `shellscript.sh`, some parts don't work as expected as if the script wasn't executed within the Bash shell, but some other more basic shell lacking certain features.

#!/bin/bash

# Parsing cli options to variables
src_path=$1
dst_path=$2
log_path=$3

# Generating file listing
dir_name="${src_path##*/}"
file_list=$(date +%Y%m%d%H%M%S)'_'$dir_name'.log'
list_dir="/home/pi/FileListings/"

# Running backup
sudo rsync -av --delete-during $src_path $dst_path >> $list_dir$file_list
status=$?

if [ $status == 0 ]; then
        echo $(date)"   Backup of $dir_name complete. For more details, check individual logs." >> $log_path
fi

I suspect that the condition in the if statement isn't evaluated properly. The error message is something along the lines of "command [0: not found". This would occur in a shell which does not support this syntax. I've also tried equivalent statements, none of which worked in this case, even though ALL of them should be correct under bash...

 

Thanks in advance

Steffen

Owner of a top of the line 13" MacBook Pro with Retina Display (Dual Boot OS X El Capitan & Win 10):
Core i7-4558U @ 3.2GHz II Intel Iris @ 1200MHz II 1TB Apple/Samsung SSD II 16 GB RAM @ 1600MHz

Link to comment
Share on other sites

Link to post
Share on other sites

Ok, so I found some useful information. Ruby calls /bin/sh instead of /bin/bash, even if the command you're executing is a script that has the correct shebang at the start...

 

Will need to see if this solves my problems... 

http://greyblake.com/blog/2013/09/21/how-to-call-bash-not-shell-from-ruby/

 

Adding this because it might help someone else in the future.

Owner of a top of the line 13" MacBook Pro with Retina Display (Dual Boot OS X El Capitan & Win 10):
Core i7-4558U @ 3.2GHz II Intel Iris @ 1200MHz II 1TB Apple/Samsung SSD II 16 GB RAM @ 1600MHz

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×