0

On my server I try run:

#!/bin/bash

PATH="/SANCFS/stats/scripts/"

for (( i=6;i<=8;i++ ));
do
   echo "Running $i"

   exec "/SANCFS/stats/scripts/load_cdrs.sh --debug --config /SANCFS/stats/scripts/iquall-mm4-cdr.cfg --date '2018-10-0"$i"' >> /home/stats/201810/load_cdrsIMRMM4-0"$i".ok 2>>/home/stats/201810/load_cdrsIMRMM4-0"$i".err"
done

And the result is:

cannot execute: No such file or directory

Your help, how edit/modify to run successfully ?

2
  • 1
    Why are you enclosing the while command line after exec in double quotes? If you do that, shell will treat the whole thing as the command name. Remove outer the double quotes and you should be good. Commented Oct 26, 2018 at 22:45
  • 1
    Unless you are certain that you don't need things like /usr/bin in your PATH, you almost certainly do not want to reset the PATH like this. If you want to add /SANCFS/stats/scripts/ to your path, write something like PATH="$PATH:/SANCFS/stats/scripts/" Commented Oct 26, 2018 at 23:04

3 Answers 3

2

Here's an easier way to reproduce your problem:

$ exec "echo "hello world""
bash: exec: echo hello: not found

Running a command in bash does not require adding exec or quotes:

$ echo "hello world"
hello world

Additionally, you are using $i in single quotes in one case, and you're overwriting the shell search path PATH for seemingly no reason. Applied to your example:

#!/bin/bash

for (( i=6;i<=8;i++ ));
do
   echo "Running $i"

  /SANCFS/stats/scripts/load_cdrs.sh --debug --config /SANCFS/stats/scripts/iquall-mm4-cdr.cfg --date "2018-10-0$i" >> /home/stats/201810/load_cdrsIMRMM4-0"$i".ok 2>>/home/stats/201810/load_cdrsIMRMM4-0"$i".err
done
Sign up to request clarification or add additional context in comments.

Comments

1

Don't use exec. That replaces the current process with the process that runs the specified command, so you won't repeat the loop. Just execute the command normally.

And the argument to exec shouldn't be all inside a single quoted string. Maybe you're confusing it with eval?

#!/bin/bash

PATH="/SANCFS/stats/scripts/"

for (( i=6;i<=8;i++ ));
do
   echo "Running $i"

   /SANCFS/stats/scripts/load_cdrs.sh --debug --config /SANCFS/stats/scripts/iquall-mm4-cdr.cfg --date 2018-10-0"$i" >> /home/stats/201810/load_cdrsIMRMM4-0"$i".ok 2>>/home/stats/201810/load_cdrsIMRMM4-0"$i".err
done

Comments

0

You could replace exec with dot ( . ) If you try the 5 options, you should see the different options

$ exec /bin/bash

$ /bin/bash
$ . /bin/bash
$ ./bin/bash
$ /bin/bash /bin/bash

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.