Results 1 to 3 of 3

Thread: Help with a bash function

  1. #1
    Join Date
    Apr 2005
    Beans
    645
    Distro
    Dapper Drake Testing/

    Help with a bash function

    Hello,

    I am trying to create a function in order to send it a command as a parameter, execute it and display the result in a dialog, it works well if

    Code:
    base_dir="/tmp"
    log="/dev/tty5"
    dialog=`which dialog`
    dorun()
    {
    	# dorun COMMAND TITLE BEGIN_TEXT END_TEXT
    	if [ "${1}" == "" ]; then
    		#WTH you need to send the command to run man!!
    		return 1
    	fi
    	FILE=${base_dir}/.dorun
    	LOCK=${base_dir}/.dolockrun
    	PID=${base_dir}/.dorunpid
    	rm -f $FILE > $log 2>&1
    	rm -f $LOCK > $log 2>&1
    	rm -f $PID > $log 2>&1
    
    	# beginning the loop
    	( \
    	echo > $FILE; \
    	touch $LOCK; \
    	if [ "${3}" != "" ]; then
    		echo $3 >> $FILE;
    	fi
    	echo >>$FILE; \
    	#$1 >> $FILE; \                                      # The problem is here somewhere in this 3 lines, i can't find it out :(
    	i=`echo $1 | sed -e "s:;:; >> \$FILE\n:g"`
    	echo -e $i; \
    	$i; \
    	if [ "${4}" != "" ]; then
    		echo $4 >> $FILE;
    	fi
    	rm -f $LOCK; \
    	) &
    	sleep 2
    	${dialog} --backtitle "$TITLE" --title $2 \
    		--no-kill --tailboxbg $FILE 18 70 2>$PID
    	while [ -f $LOCK ]; do
    		sleep 1
    	done
    	kill `cat $PID`
    	${dialog} --backtitle "$TITLE" --title $2 \
    		--exit-label "Continue" --textbox $FILE 18 70
    	# fix the stair-stepping that --tailboxbg leaves us with
    	stty onlcr
    
    	#rm -f $FILE $LOCK $PID
    }
    
    dorun "date ; sleep 10 ; date ; sleep 4" "Test" "begin test" "end test"
    i tried also
    Code:
    ( $i ) >> $FILE
    i don't get what am doing wrong, but i get a weird error everytime i run it, comlaining about date; no such command
    [My Blog] | [My Sites] | [My Ubuntu Guides]

    doc.gwos.org, the real successor of Ubuntu Guide

  2. #2
    Join Date
    Apr 2005
    Beans
    645
    Distro
    Dapper Drake Testing/

    Re: Help with a bash function

    Never mind, it worked
    [My Blog] | [My Sites] | [My Ubuntu Guides]

    doc.gwos.org, the real successor of Ubuntu Guide

  3. #3
    Join Date
    Jun 2005
    Location
    Umeå, Sweden
    Beans
    475
    Distro
    Ubuntu 12.10 Quantal Quetzal

    Re: Help with a bash function

    Quote Originally Posted by Gandalf
    Never mind, it worked
    You opened up this thread just to brag about your script, didn't you. *jokingly*

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •