Sponsored Content
Top Forums Shell Programming and Scripting Improving repetitive tasks in function Post 303026939 by Don Cragun on Wednesday 5th of December 2018 09:54:42 AM
Old 12-05-2018
I don't know that this "improves" anything, but maybe it makes it more obvious that the same operations are performed for each service:
Code:
stop_service ()
{	for service in video audio stream images browser youtube
	do	sudo systemctl is-active --quiet "$service".service &&
		    sudo systemctl stop "$service".service &&
		    sudo rm /etc/systemd/system/"$service".service &&
		    echo "stop $service"
	done
}

This User Gave Thanks to Don Cragun For This Post:
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Repetitive Tasks

Could someone tell me how I can simplify the script that follows!!! I know that there must be a way how to grep Average from sar01.................. sar02 ....................... sar03....................... sar04... (3 Replies)
Discussion started by: JairGuerra
3 Replies

2. Shell Programming and Scripting

Repetitive Tasks: using if..then inside a loop

I thought I was getting pretty good with Bash but this problem is stumping me. Any suggestions would be greatly appreciated. I've written a firewall script that uses a lot of functions. The variables are read into the script from another .conf file earlier on in the code. Most of these... (2 Replies)
Discussion started by: garak
2 Replies

3. Shell Programming and Scripting

Count if numbers are not repetitive

Hi All, I have an input below and i would want to do a count on all the term "aaa" and count only once if the number in first column is the same. For eg, if i use a "grep -c aaa input" command, the count will be "8". However, i would want the count to be "6" instead since 2 numbers in the 1st... (7 Replies)
Discussion started by: Raynon
7 Replies

4. Shell Programming and Scripting

Perl Repetitive Pattern Matching

Problem: GIVEN ======= my $sql="INSERT INTO table_nm(a, b, b, d, e, f , g) VALUES (2046, TODAY, 'Change Subscription Name', '00000000000002000000000000000000000000000000000000', '00000000000001000000000000000000000000000000000000', '00000000000000000000000000000000000000000000000000', 1);... (2 Replies)
Discussion started by: Niroj
2 Replies

5. Shell Programming and Scripting

Unix Remove repetitive alphabets

Hi, I am trying to write a script that will take 2 or more instances of repetitive alphabets (ZZ) to be removed from a field. This should only happen from beginning and end of a field. For Example : Input File a) ZZZIBM Corporation b) ZZZIBM Corporation ZZZZZ b) IBM ZZZ... (26 Replies)
Discussion started by: msalam65
26 Replies

6. Shell Programming and Scripting

Improving this validate function

Hi guys, I use this function which was provided to me by someone at this site. It works perfectly for validating a users input option against allowed options.. example: validateInput "1" "1 3 4 5" would return 0 (success) function validateInput { input=$1 allowedInput=$2 for... (4 Replies)
Discussion started by: pyscho
4 Replies

7. Shell Programming and Scripting

Print lines between two repetitive patterns

Hi users I have one file which has number of occurrence of one pattern examples Adjustmenttype,11 xyz 10 dwe 9 abd 13 def 14 Adjustmenttype,11 xyz 24 dwe 34 abd 35 def 11 nmb 12 Adjustmenttype, not eleven .... ... ... (2 Replies)
Discussion started by: eranmoh
2 Replies

8. UNIX for Dummies Questions & Answers

Repetitive scripts within a bash shell

I have a bash shell that even though it does not look pretty is working very well. Some of the steps are repetitive, something like this: muscle -in ${e}.4 > $e.5 read -t1 sed ':a /^>/!N;s/\n\(\)/\1/;ta' $e.5 > $e.6 read -t2 awk '/>/{fr=$3;getline;n=split ($0,a,""); for (i=1;i<=n;i++)... (2 Replies)
Discussion started by: Xterra
2 Replies

9. Shell Programming and Scripting

Repetitive ending of script

Hi, I am quit satisfied with this scrtipt and really don't want to change anything but the end. I get a repetitve option when I want to "quit" and don't know why. What am I missing? When I press q to quit with this script, I get an EXTRA "Enter " How do I correct this so that when I press... (1 Reply)
Discussion started by: jefferj54
1 Replies

10. Shell Programming and Scripting

I need help to removing repetitive lines

Hello SuperUsers! First i wanna say my english sucks.. Don't hate me for that. :rolleyes: I need to make a Bash for removing smilar lines from an output file. My output file always same. Line 1 & 2 Stays. And others similar to this lines needs to be delete. </UsageData><?xml version="1.0"... (4 Replies)
Discussion started by: morphin
4 Replies
SYSTEMD-HALT.SERVICE(8) 				       systemd-halt.service					   SYSTEMD-HALT.SERVICE(8)

NAME
systemd-halt.service, systemd-poweroff.service, systemd-reboot.service, systemd-kexec.service, systemd-shutdown - System shutdown logic SYNOPSIS
systemd-halt.service systemd-poweroff.service systemd-reboot.service systemd-kexec.service /lib/systemd/systemd-shutdown /lib/systemd/system-shutdown/ DESCRIPTION
systemd-halt.service is a system service that is pulled in by halt.target and is responsible for the actual system halt. Similarly, systemd-poweroff.service is pulled in by poweroff.target, systemd-reboot.service by reboot.target and systemd-kexec.service by kexec.target to execute the respective actions. When these services are run, they ensure that PID 1 is replaced by the /lib/systemd/systemd-shutdown tool which is then responsible for the actual shutdown. Before shutting down, this binary will try to unmount all remaining file systems, disable all remaining swap devices, detach all remaining storage devices and kill all remaining processes. It is necessary to have this code in a separate binary because otherwise rebooting after an upgrade might be broken -- the running PID 1 could still depend on libraries which are not available any more, thus keeping the file system busy, which then cannot be re-mounted read-only. Immediately before executing the actual system halt/poweroff/reboot/kexec systemd-shutdown will run all executables in /lib/systemd/system-shutdown/ and pass one arguments to them: either "halt", "poweroff", "reboot" or "kexec", depending on the chosen action. All executables in this directory are executed in parallel, and execution of the action is not continued before all executables finished. Note that systemd-halt.service (and the related units) should never be executed directly. Instead, trigger system shutdown with a command such as "systemctl halt" or suchlike. SEE ALSO
systemd(1), systemctl(1), systemd.special(7), reboot(2), systemd-suspend.service(8) systemd 237 SYSTEMD-HALT.SERVICE(8)
All times are GMT -4. The time now is 03:37 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy