LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 11-22-2012, 12:56 PM   #1
whositwhatnow
Member
 
Registered: Mar 2012
Distribution: RHEL 5/6
Posts: 56

Rep: Reputation: Disabled
Question 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
 
Old 11-22-2012, 12:58 PM   #2
TobiSGD
Moderator
 
Registered: Dec 2009
Location: Germany
Distribution: Whatever fits the task best
Posts: 17,148
Blog Entries: 2

Rep: Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886
And what exactly is your problem with doing that?
 
Old 11-22-2012, 01:00 PM   #3
whositwhatnow
Member
 
Registered: Mar 2012
Distribution: RHEL 5/6
Posts: 56

Original Poster
Rep: Reputation: Disabled
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
 
Old 11-22-2012, 01:01 PM   #4
whositwhatnow
Member
 
Registered: Mar 2012
Distribution: RHEL 5/6
Posts: 56

Original Poster
Rep: Reputation: Disabled
So this is what i tried:

cp file file.bak
edit.pl > file
/etc/init.d/service restart
 
Old 11-22-2012, 01:17 PM   #5
TobiSGD
Moderator
 
Registered: Dec 2009
Location: Germany
Distribution: Whatever fits the task best
Posts: 17,148
Blog Entries: 2

Rep: Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886
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.
 
Old 11-22-2012, 01:20 PM   #6
whositwhatnow
Member
 
Registered: Mar 2012
Distribution: RHEL 5/6
Posts: 56

Original Poster
Rep: Reputation: Disabled
Perl interpreter?
 
Old 11-22-2012, 01:42 PM   #7
whositwhatnow
Member
 
Registered: Mar 2012
Distribution: RHEL 5/6
Posts: 56

Original Poster
Rep: Reputation: Disabled
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.
 
Old 11-22-2012, 02:04 PM   #8
whositwhatnow
Member
 
Registered: Mar 2012
Distribution: RHEL 5/6
Posts: 56

Original Poster
Rep: Reputation: Disabled
this is what i have

perl -x '/etc/somedata/primary/addtofile.pl' > 'newfile'
/etc/init.d/named restart
 
Old 11-22-2012, 04:46 PM   #9
TobiSGD
Moderator
 
Registered: Dec 2009
Location: Germany
Distribution: Whatever fits the task best
Posts: 17,148
Blog Entries: 2

Rep: Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886
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.
 
  


Reply



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
Help Creating Script gizza23 Linux - General 4 11-27-2007 09:17 PM
Need help in with creating a script. xtremeclones Linux - Software 10 10-01-2007 05:34 AM
Help in creating an .sh script wild_oscar Programming 5 06-04-2007 06:17 AM
help creating a script... minm Linux - Newbie 5 01-09-2005 12:27 AM
creating shell script that executes as root regardless of who runs the script? m3kgt Linux - General 13 06-04-2004 10:23 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 01:29 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
Open Source Consulting | Domain Registration