LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Need help creating a script (https://www.linuxquestions.org/questions/linux-newbie-8/need-help-creating-a-script-4175438313/)

whositwhatnow 11-22-2012 12:56 PM

Need help creating a script
 
Hello i'm not strong at programming and scripting in linux so i'm hoping you csan help me.


i have a script that runs a restart command for a service. I want to add additional functions before it restarts this service.

e.g

file called script restart

in file now that works:

/etc/init.d/service restart

I want to add to functions ahead of this restart command:

cp file file.bak overwrite existing file quietly
run edit.pl > file
teh /etc/init.d/service restart

TobiSGD 11-22-2012 12:58 PM

And what exactly is your problem with doing that?

whositwhatnow 11-22-2012 01:00 PM

I do not know the proper syntaxt to be able to do this. I'm reading i have to use backticks, but even when i jsut put those lines in it does not work

whositwhatnow 11-22-2012 01:01 PM

So this is what i tried:

cp file file.bak
edit.pl > file
/etc/init.d/service restart

TobiSGD 11-22-2012 01:17 PM

Looks like it should work, as long as the perl-script in there has a proper shebang. Otherwise you need to start it with the Perl interpreter.

Please post what exactly you are doing and which error-messages exactly you are getting.

whositwhatnow 11-22-2012 01:20 PM

Perl interpreter?

whositwhatnow 11-22-2012 01:42 PM

I have an application that calls on this script called restart. In that file it is a shortcut to restarting the service, and i want to add those 2 functions to that script. So once the application calls that script it makes a copy of a file, runs teh perl script and restarts the service.

whositwhatnow 11-22-2012 02:04 PM

this is what i have

perl -x '/etc/somedata/primary/addtofile.pl' > 'newfile'
/etc/init.d/named restart

TobiSGD 11-22-2012 04:46 PM

We still don't know what the errors are you get. Without that nobody can help.
Also, those single quotes are not needed, so just remove them.


All times are GMT -5. The time now is 09:23 PM.