LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 07-27-2006, 05:25 AM   #1
activeq
Member
 
Registered: Jul 2006
Location: Balen, Belgium
Distribution: Suse 10, Centos, Open Solaris
Posts: 76

Rep: Reputation: 15
bash, starting a command in script


Hi there,

I'm trying to make a script in bash. I've made a few before and they work.
But now I want to make a script that start a command, but I can't figure out how to do.

If I type the command via CLI it works, but I want that command in a script, so I can put is in Crontab.

the script looks like this:

---------------------------------------------------------------------
#!/bin/bash

/usr/local/sarab/sarab.sh /etc/sarab/test/sarab.conf

---------------------------------------------------------------------

Something have to go before '/usr/local/'etc etc
I tried "start" "run" etc...but all didn't work.

please help
 
Old 07-27-2006, 05:59 AM   #2
konsolebox
Senior Member
 
Registered: Oct 2005
Distribution: Gentoo, Slackware, LFS
Posts: 2,245
Blog Entries: 16

Rep: Reputation: 233Reputation: 233Reputation: 233
what do you mean? start a command from input? maybe you're talking about exec. do
Code:
help exec
 
Old 07-27-2006, 06:23 AM   #3
activeq
Member
 
Registered: Jul 2006
Location: Balen, Belgium
Distribution: Suse 10, Centos, Open Solaris
Posts: 76

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by konsolebox
what do you mean? start a command from input? maybe you're talking about exec. do
Code:
help exec
I've made a backup server using dar & sarab. it will backup my mailserver, fileserver and webservers sql files.

Because i want to seperate the backup for all 3 servers, I have to specify where the sarab.conf is after the basic command /usr/local/sarab/sarab.sh.
So if I only need to backup 1 server the command /usr/local/sarab/sarab.sh was enough to run the backup. For the second server, I need to specify the path of sarab.conf after the basic command.

It works if I type /usr/local/sarab/sarab.sh /etc/sarab/test/sarab.conf from the command line.
My second server will be backupped.

Now i want to put this in cron.
when I put 13 10 * * 2-6 /usr/local/sarab/sarab.sh in cron it works.
When I put 13 10 * * 2-6 /usr/local/sarab/sarab.sh /etc/sarab/test/sarab.conf it doesn't work.

that's why I thought to make a script to execute that last command and put the script in cron.

I tried to put exec in fron of the command, but that didn't work either.

please help
 
Old 07-27-2006, 06:34 AM   #4
konsolebox
Senior Member
 
Registered: Oct 2005
Distribution: Gentoo, Slackware, LFS
Posts: 2,245
Blog Entries: 16

Rep: Reputation: 233Reputation: 233Reputation: 233
ok i've already done this before but i need to recall the situation and how i did it so just bear with me.

about the script that you made. did you specify the full path? the PATH variable in cron's environment is incomplete btw.

also please post the script so that i'll see what didn't work.
 
Old 07-27-2006, 06:40 AM   #5
activeq
Member
 
Registered: Jul 2006
Location: Balen, Belgium
Distribution: Suse 10, Centos, Open Solaris
Posts: 76

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by konsolebox
ok i've already done this before but i need to recall the situation and how i did it so just bear with me.

about the script that you made. did you specify the full path? the PATH variable in cron's environment is incomplete btw.

also please post the script so that i'll see what didn't work.

Maybe i don't understand.
The script called sarab.sh is automaticly installed after installing sarab. that script works and needs no modification.

The extension /etc/sarab/test/sarab.conf is the problem. if I add that in cron or in a script, the backup will not start.

the only thing I have in my script is this:

#!/bin/bash

/usr/local/sarab/sarab.sh /etc/sarab/test/sarab.conf

so the above command have to be in a script, so I can cron and execute it. It works via shell only not in cron or script.

Last edited by activeq; 07-27-2006 at 06:43 AM.
 
Old 07-27-2006, 07:12 AM   #6
konsolebox
Senior Member
 
Registered: Oct 2005
Distribution: Gentoo, Slackware, LFS
Posts: 2,245
Blog Entries: 16

Rep: Reputation: 233Reputation: 233Reputation: 233
you're probably missing some of the required environmental variables, we must find a way to get them. we can try this one:

Code:
#!/bin/bash

export PATH="${PATH}:/usr/local/sbin:/usr/local/bin"

exec bash /usr/local/sarab/sarab.sh /etc/sarab/test/sarab.conf
then save this as sarahcron.sh or anything you like. chmod +x the file. after that set sarahcron.sh in cron (full path of course).

there is an option in bash that loads the normal rc files. perhaps it was --login. if we only know, we'll no longer need to add the PATH statement.
 
Old 07-27-2006, 07:38 AM   #7
activeq
Member
 
Registered: Jul 2006
Location: Balen, Belgium
Distribution: Suse 10, Centos, Open Solaris
Posts: 76

Original Poster
Rep: Reputation: 15
did didn't work either
 
Old 07-27-2006, 08:29 AM   #8
konsolebox
Senior Member
 
Registered: Oct 2005
Distribution: Gentoo, Slackware, LFS
Posts: 2,245
Blog Entries: 16

Rep: Reputation: 233Reputation: 233Reputation: 233
try redirecting the output to /dev/null. i've also completed export for you:

Code:
#!/bin/bash

export PATH="/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin"

exec /bin/bash /usr/local/sarab/sarab.sh /etc/sarab/test/sarab.conf >/dev/null 2>&1
if this won't work, make a log

Code:
#!/bin/bash

echo a >/var/log/sarab

export PATH="/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin"

echo b >>/var/log/sarab

/usr/local/sarab/sarab.sh /etc/sarab/test/sarab.conf >/dev/null 
2>&1
echo c >>/var/log/sarab
there is an another option. make a duplicate copy of the /usr/local/sarab/sarab.sh then modify the replica in which /etc/sarab/test/sarab.conf is set as the default argument. run the replica afterwards. example '/usr/local/sarab/sarab2.sh

example if you have a code like this:
Code:
CONF_ARG=$1
# change this to
CONF_ARG=/etc/sarab/test/sarab.conf
 
Old 07-27-2006, 09:37 AM   #9
activeq
Member
 
Registered: Jul 2006
Location: Balen, Belgium
Distribution: Suse 10, Centos, Open Solaris
Posts: 76

Original Poster
Rep: Reputation: 15
Finally...I found it.

Your last suggestion put me on the right track.

In the sarab.sh file it say the following:

else
# Use the deafult location of sarab.conf
SARAB_CONF="/etc/sarab/sarab.conf"

I changed it in:

else
# Use the deafult location of sarab.conf
SARAB_CONF="/etc/sarab/test/sarab.conf"

That was all i had to do.

Now I can change this setting for every server and put only /usr/local/sarab/sarabx.sh (x = variable)

Manny thanks for you help
 
Old 07-27-2006, 09:42 AM   #10
konsolebox
Senior Member
 
Registered: Oct 2005
Distribution: Gentoo, Slackware, LFS
Posts: 2,245
Blog Entries: 16

Rep: Reputation: 233Reputation: 233Reputation: 233
you're welcome. til next time.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
BASH script for starting printer ylikone Programming 2 06-01-2006 05:56 AM
Bash Script; command not found twintornado Programming 2 06-01-2005 10:59 AM
Bash backup script - If multiple files starting with a exist problem demoncheese Programming 2 07-29-2004 11:47 PM
Simple Bash Script Help Command kemplej Linux - Software 1 03-11-2004 04:52 AM
Starting a service in a bash script AMMullan Programming 3 02-19-2004 12:06 PM


All times are GMT -5. The time now is 06:00 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration