Script works with bash 3.0 but not 3.2.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script works with bash 3.0 but not 3.2.
# 1  
Old 03-20-2009
Script works with bash 3.0 but not 3.2.

Hello,

So my knowledge of bash scripting is not that great and I have been trying to solve this problem on my own for awhile to no avail.



Here's the error I get when running it with an OS that uses bash 3.2.x:

testagain.sh: line 10: *-1: syntax error: operand expected (error token is "*-1")



Here's the script (sorry for the lack of indents not sure how the formatting on this forum works):

Code:
#!/bin/bash

cd /home/sites

for logdir in */logs; do
        
        for access_log in ${logdir}/access_log.*; do
              
                lognum=`echo $access_log | sed -e 's/.*access_log\.//'`;
                lognum=$(($lognum-1));
                mv $access_log ${logdir}/access_log-$(date -d"- $lognum  days" '+%Y%m%d');

        done

done


Last edited by fpmurphy; 03-20-2009 at 11:49 AM.. Reason: Added code blocks
# 2  
Old 03-20-2009
It appears that the following line is returning an unexpected value
Code:
lognum=`echo $access_log | sed -e 's/.*access_log\.//'`;

You can check by adding a "echo $lognum" statement
# 3  
Old 03-20-2009
Problem solved, had to add something to the script to make sure directories were not empty. Thanks again for your help!

Last edited by forkandspoon; 03-20-2009 at 01:39 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Command works interactively but not in bash script

The below command works in the terminal interactively but not as part of a bash script. I though maybe I needed to escape the "$dir" so it isn't interpreted literally, but that's not it. Thank you :). interactively in terminal dir=/path/to new=$(ls "$dir"/*.csv -tr | tail -n 1) && echo... (6 Replies)
Discussion started by: cmccabe
6 Replies

2. Shell Programming and Scripting

How to block first bash script until second bash script script launches web server/site?

I'm new to utilities like socat and netcat and I'm not clear if they will do what I need. I have a "compileDeployStartWebServer.sh" script and a "StartBrowser.sh" script that are started by emacs/elisp at the same time in two different processes. I'm using Cygwin bash on Windows 10. My... (3 Replies)
Discussion started by: siegfried
3 Replies

3. Shell Programming and Scripting

Shell script works fine as a standalone script but not as part of a bigger script

Hello all, I am facing a weird issue while executing a code below - #!/bin/bash cd /wload/baot/home/baotasa0/sandboxes_finance/ext_ukba_bde/pset sh UKBA_publish.sh UKBA 28082015 3 if then echo "Param file conversion for all the areas are completed, please check in your home directory"... (2 Replies)
Discussion started by: ektubbe
2 Replies

4. Shell Programming and Scripting

Script in bash that works only some of the time

I ran this script yesterday (in the background) /usr/bin/nohup myfilelocation/myscriptname.sh & the script worked perfectly. i ran it today (also in the background) and just sat there. So i killed it and ran it normally and it worked perfectly. Anyone suggest why it just sat there and... (8 Replies)
Discussion started by: twinion
8 Replies

5. Shell Programming and Scripting

Sourcing Env file with eval works with ksh but not BASH

Hi, I am running this on Redhat 5.10 I have a simple test script called test.sh which has the following contents and it uses the BASH shebang. ------------------------------------------------------------- #!/bin/bash eval `/tmp/filereader.pl /tmp/envfile.txt` echo "TESTPATH=$TESTPATH" ... (28 Replies)
Discussion started by: waavman
28 Replies

6. Shell Programming and Scripting

Calling bash script works when called manually but not via Cron?

Hi, I've got a Bash backup script I'm trying to run on a directory via a cron job nightly. If I ssh in and run the script manually it works flawlessly. If I set up the cron to run evertything is totally messed up I don't even know where to begin. Basically the path structure is ... (6 Replies)
Discussion started by: wyclef
6 Replies

7. UNIX for Dummies Questions & Answers

Bash script dont works when executed as cronjob

Hello, i have cronjob: crontab -l * * * * * pkill -f domexpcheck;sh /root/dom/domexpcheck.sh it runs: /var/log/cron Mar 25 12:11:01 vps crond: (root) CMD (pkill -f domexpcheck;sh /root/dom/domexpcheck.sh) but somehow script dont run properly via cronjob. But when i execute cronjob... (7 Replies)
Discussion started by: postcd
7 Replies

8. UNIX for Dummies Questions & Answers

Error: `mv olddir/ newdir/ ` never works on new version of bash?

Suppose you have a directory called "olddir" exists but no "newdir", you want to rename "olddir" to"newdir" In previous versions (at least in 2.05b.0) of bash, you can try mv olddir/ newdir/ OR mv olddir/ newdir But in new versions of bash, if you mv olddir/ newdir/ BASH panics: mv:... (5 Replies)
Discussion started by: meili100
5 Replies

9. Shell Programming and Scripting

Works from bash prompt, but not from script!

I'm trying to use unison from bash on windows with cygwin. I don't know if this is a cygwin question, bash question or unison question. Since I always get reprimanded by the cygwin mailing list for assuming it is a cygwin problem, I'll assume it is a bash question. The following commands work... (7 Replies)
Discussion started by: siegfried
7 Replies

10. Shell Programming and Scripting

substring command works but only in BASH shell

I am having trouble running a .sh file. The code 'x=${file_name:0:$z-11}' is giving me a bad substitution error. However when I run in BASH it works. Thing is when this goes to production the .sh will not be running in BASH. Is there a way to substring a string not in BASH or a way to invoke... (2 Replies)
Discussion started by: edwardtk11
2 Replies
Login or Register to Ask a Question