Small automation


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Small automation
# 1  
Old 07-24-2013
Linux sample script to start or stop any service

Frequently we need to stop or start services on Linux systems.

For exmaple : To start or stop vsftpd daemon

Code:
# /etc/init.d/vsftpd start

or

Code:
# /etc/init.d/vsftpd stop

Following script will check the vsftpd service and if it is running, it will be stopped or vice-versa.

Code:
# cat /bin/vsftpd

Code:
#!/bin/bash
/etc/init.d/vsftpd status|grep running
if
[ "$?" == "0" ]; then
/etc/init.d/vsftpd stop
else
/etc/init.d/vsftpd start
fi

Code:
# chmod 500 /bin/vsftpd

Now we can run just

Code:
# vsftpd

I hope this small script will save some microseconds of our busy schedule Smilie

Last edited by snjksh; 07-24-2013 at 06:27 AM.. Reason: Code tags
# 2  
Old 07-24-2013
I don't think I would call it something so confusing. Smilie Perhaps put it in /usr/local/bin to segregate it from anything supplied. I can't actually see the value of flipping it on/off when you would want to know the current state to decide what to do next anyway. SmilieSmilie

If you need to stop/start, then you would have to run your script twice hoping that it is already running. You could just issue:-
Code:
service vsftpd restart

This will always leave it running (unless there is a start-up error)



I hope that this helps. Smilie


Robin
Liverpool/Blackburn
UK
# 3  
Old 07-24-2013
Linux

Thanks Robin.

It seems that I was not able to explain need of this script. Let me try again ...

Objective of the script is not to restart the vsftpd service. Rather to minimize the typing of long command.

Actually I have to stop or start ( not restart ) vsftpd daemon on some server frequently.

So I thought of writing this small script to save my time.Smilie
# 4  
Old 07-24-2013
Does your init.d script not accept the restart command?
# 5  
Old 07-25-2013
What's wrong with just making a choice between:-
Code:
service vsftpd stop
service vsftpd start

That way you will be certain what state you are going to. You could always put these as an alias thus:-
Code:
alias ftpoff="service vsftpd stop"
alias ftpon="service vsftpd start"

Would that not be neater?



Robin
This User Gave Thanks to rbatte1 For This Post:
# 6  
Old 07-29-2013
Robin : your option is better than mine. I will certainly use that.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Post Here to Contact Site Administrators and Moderators

UNIX automation

I am using netteza server and i have a list of table names. I need to fetch all the data from these tables and need to create seperate zip files and store in a folder in the server. How can we automate this process. (1 Reply)
Discussion started by: nikhilthms97
1 Replies

2. Shell Programming and Scripting

Automation script

Hello All , I came across a tricky solution to devolop . Here is a part of the requirement automation . I have different set of server say : Web ( has 4 servers under it ) , App ( has 4 servers under it ) , DB ( has 2 servers under it ) Above each i have different load balancers , Say : Web... (4 Replies)
Discussion started by: radha254
4 Replies

3. Shell Programming and Scripting

scp Automation

Hi, I have a requirement to automate SCP command. I have to write the scp command in server1 to copy file from server2 and paste it in server3. I will be passing server2 and server3 as variables. Pls suggest. (1 Reply)
Discussion started by: usrrenny
1 Replies

4. Shell Programming and Scripting

CVS Automation

Hi All, I am just looking for CVS automation for SQL scripts. Normally Devs will check in new sql scripts or they will update the existing sql scripts with new query. We will take the scripts from CVS and run in DB. I am thinking to automate that process like whenever a new script is checked in... (1 Reply)
Discussion started by: pvmanikandan
1 Replies

5. UNIX for Dummies Questions & Answers

CUPs automation

A little background information: We are a company that uses Sharp MFP devices for everyone to print on. We have a lot of MAC BYOD devices. All printing is done through a product called PaperCut which is ran on a Windows 2008 R2 server. Sharp charges our company for each print job done in... (1 Reply)
Discussion started by: jdmorecraft
1 Replies

6. Shell Programming and Scripting

automation using python

Im trying to write an automation script using python. I expect this script to log in to a remote server, execute commands and get its output. import pexpect child=pexpect.spawn('ssh myuser@192.168.151.80') child.expect('Password:') child.sendline('mypassword') get_output =... (4 Replies)
Discussion started by: Arun_Linux
4 Replies

7. UNIX for Advanced & Expert Users

Need help in automation

Hi, I wanted to automate the scp command where i do not want to enter the password each time. So thought of using expect command. Script is executing without any issues but files are not copied to remote server. Can any one help me? Below is my shell script.. #!/bin/ksh ... (6 Replies)
Discussion started by: balasubramani04
6 Replies

8. Shell Programming and Scripting

Scripting for automation

Hi, I would like to know about a automated script which would collect data on a regular day to day basis at a particular time and stores it in a defined path for business analysis. Any help on this is highly appreciable!! Thanks Sara (6 Replies)
Discussion started by: sara23
6 Replies

9. Shell Programming and Scripting

UNIX automation

Hello People, I have an outstanding issue with me I have 5 files at location /usr/abc called 1.DE 1.TXT 2.DE 2.TXT 3.DE 3.TXT 4.DE 4.TXT 5.Fe.ok My work involves few manual process like transfer 1.DE 1.TXT and 5.Fe.ok to /usr/dob location and run one script(for example -... (42 Replies)
Discussion started by: j_panky
42 Replies

10. Shell Programming and Scripting

Help in automation...

Hi All, I need to run the same command on many servers. I am using ssh for the same. Following is the script that I am using to fire the same command on multiple machines. #!/bin/bash # Linux/UNIX box with ssh key based login #SERVERS="iqmevrick,iqmango" # SSH User name USR="root" #... (1 Reply)
Discussion started by: nua7
1 Replies
Login or Register to Ask a Question