Force commands to run in parallel even without -j? - gnu-make

I know that if I put this in my Makefile
a: b c
Then run make -j2 a then it will run b and c in parallel, but what if I always want b and c to run in parallel, even if the user doesn't include -j >= 2?
In my scenario, b and c are actually daemons that never complete, so I need them to run in parallel. I don't want them to run in the background either.

It's an odd use of make, but if you want to do it with make,
given that b and c are .PHONY, you could do so like:
.PHONY: a b c
a:
$(MAKE) -j2 b c
b c:
while [ "1" ]; do echo "$#: $$(date)"; sleep 1; done
A rule:
a: b c
isn't to the purpose. It says that a depends on b (being done) and
a depends on c (being done), but you don't want that at all. You
just want a to denote the concurrent execution of the recipes for
b and c.
You get:
$ make b
while [ "1" ]; do echo "b: $(date)"; sleep 1; done
b: Wed Mar 9 18:29:55 GMT 2016
b: Wed Mar 9 18:29:56 GMT 2016
b: Wed Mar 9 18:29:57 GMT 2016
b: Wed Mar 9 18:29:58 GMT 2016
b: Wed Mar 9 18:29:59 GMT 2016
^CMakefile:7: recipe for target 'b' failed
make: *** [b] Interrupt
$ make c
while [ "1" ]; do echo "c: $(date)"; sleep 1; done
c: Wed Mar 9 18:30:38 GMT 2016
c: Wed Mar 9 18:30:39 GMT 2016
c: Wed Mar 9 18:30:40 GMT 2016
c: Wed Mar 9 18:30:41 GMT 2016
c: Wed Mar 9 18:30:42 GMT 2016
^CMakefile:7: recipe for target 'c' failed
make: *** [c] Interrupt
$ make a
make -j2 b c
make[1]: Entering directory '/home/imk/develop/so/parallel_make'
while [ "1" ]; do echo "b: $(date)"; sleep 1; done
while [ "1" ]; do echo "c: $(date)"; sleep 1; done
b: Wed Mar 9 18:31:13 GMT 2016
c: Wed Mar 9 18:31:13 GMT 2016
b: Wed Mar 9 18:31:14 GMT 2016
c: Wed Mar 9 18:31:14 GMT 2016
b: Wed Mar 9 18:31:15 GMT 2016
c: Wed Mar 9 18:31:15 GMT 2016
b: Wed Mar 9 18:31:16 GMT 2016
c: Wed Mar 9 18:31:16 GMT 2016
b: Wed Mar 9 18:31:17 GMT 2016
c: Wed Mar 9 18:31:17 GMT 2016
^CMakefile:7: recipe for target 'b' failed
make[1]: *** [b] Interrupt
Makefile:7: recipe for target 'c' failed
make[1]: *** [c] Interrupt
Makefile:4: recipe for target 'a' failed
make: *** [a] Interrupt

Related

OpenVPN Server TCP_CLIENT link local: (not bound)

I've been trying to set up an OpenVPN server on my Linux recently but I continuously get the same error every time I try to connect to my server.
My settings are like this:
proto tcp
port 443
resolv-retry infinite
nobind
user nobody
group nogroup
cipher AES-256-CBC
auth SHA256
script-security 2
up /etc/openvpn/update-systemd-resolved
down /etc/openvpn/update-systemd-resolved
down-pre
dhcp-option DOMAIN-ROUTE .
I have checked the settings on my server and local computer a million times and all of them are the same. Still don't know what I have to do about it. Thanks in advance! :*
Sat Nov 27 23:45:11 2021 OpenVPN 2.4.7 x86_64-pc-linux-gnu [SSL (OpenSSL)] [LZO] [LZ4] [EPOLL] [PKCS11] [MH/PKTINFO] [AEAD] built on Jul 19 2021
Sat Nov 27 23:45:11 2021 library versions: OpenSSL 1.1.1f 31 Mar 2020, LZO 2.10
Sat Nov 27 23:45:11 2021 NOTE: the current --script-security setting may allow this configuration to call user-defined scripts
Sat Nov 27 23:45:11 2021 TCP/UDP: Preserving recently used remote address: [AF_INET]myserverip:443
Sat Nov 27 23:45:11 2021 Socket Buffers: R=[131072->131072] S=[16384->16384]
Sat Nov 27 23:45:11 2021 Attempting to establish TCP connection with [AF_INET]myserverip:443 [nonblock]
Sat Nov 27 23:45:12 2021 TCP connection established with [AF_INET]myserverip:443
Sat Nov 27 23:45:12 2021 TCP_CLIENT link local: (not bound)
Sat Nov 27 23:45:12 2021 TCP_CLIENT link remote: [AF_INET]myserverip:443
Sat Nov 27 23:45:12 2021 NOTE: UID/GID downgrade will be delayed because of --client, --pull, or --up-delay
Sat Nov 27 23:45:12 2021 Connection reset, restarting [0]
Sat Nov 27 23:45:12 2021 SIGUSR1[soft,connection-reset] received, process restarting
Sat Nov 27 23:45:12 2021 Restart pause, 5 second(s)

How can I write a shell scripts that calls another script for each day starting from start date upto current date [duplicate]

This question already has answers here:
How to loop through dates using Bash?
(10 answers)
Closed 1 year ago.
How can I write a shell scripts that calls another script for each day
i.e currently have
#!/bin/sh
./update.sh 2020 02 01
./update.sh 2020 02 02
./update.sh 2020 02 03
but I want to just specify start date (2020 02 01) and let is run update.sh for every day upto current date, but don't know how to manipulate date in shell script.
I made a stab at it, but rather messy, would prefer if it could process date itself.
#!/bin/bash
for j in {4..9}
do
for k in {1..9}
do
echo "update.sh" 2020 0$j 0$k
./update.sh 2020 0$j 0$k
done
done
for j in {10..12}
do
for k in {10..31}
do
echo "update.sh" 2020 $j $k
./update.sh 2020 $j $k
done
done
for j in {1..9}
do
for k in {1..9}
do
echo "update.sh" 2021 0$j 0$k
./update.sh 2021 0$j 0$k
done
done
for j in {1..9}
do
for k in {10..31}
do
echo "update.sh" 2021 0$j $k
./update.sh 2021 0$j $k
done
done
You can use date to convert your input dates into seconds in order to compare. Also use date to add one day.
#!/bin/bash
start_date=$(date -I -d "$1") # Input in format yyyy-mm-dd
end_date=$(date -I) # Today in format yyyy-mm-dd
echo "Start: $start_date"
echo "Today: $end_date"
d=$start_date # In case you want start_date for later?
end_d=$(date -d "$end_date" +%s) # End date in seconds
while [ $(date -d "$d" +%s) -le $end_d ]; do # Check dates in seconds
# Replace `echo` in the below with your command/script
echo ${d//-/ } # Output the date but replace - with [space]
d=$(date -I -d "$d + 1 day") # Next day
done
In this example, I use echo but replace this with the path to your update.sh.
Sample output:
[user#server:~]$ ./dateloop.sh 2021-08-29
Start: 2021-08-29
End : 2021-09-20
2021 08 29
2021 08 30
2021 08 31
2021 09 01
2021 09 02
2021 09 03
2021 09 04
2021 09 05
2021 09 06
2021 09 07
2021 09 08
2021 09 09
2021 09 10
2021 09 11
2021 09 12
2021 09 13
2021 09 14
2021 09 15
2021 09 16
2021 09 17
2021 09 18
2021 09 19
2021 09 20

file manipulation unix

cat sample_file.txt(Extracted job info from Control-M)
upctm,pmdw_bip,pmdw_bip_mnt_35-FOLDistAutoRpt,Oct 7 2019 4:45 AM,Oct 7 2019 4:45 AM,1,1,Oct 6 2019 12:00 AM,Ended OK,3ppnc
upctm,pmdw_ddm,pmdw_ddm_dum_01-StartProjDCSDemand,Oct 17 2019 4:02 AM,Oct 17 2019 4:02 AM,3,1,Oct 16 2019 12:00 AM,Ended OK,3pqgq
I need to process this file into DB table(Oracle)
Bu I need to make sure that day is 2 number (example 7 to 07).
(example: Oct 07 2019 6:32 AM)
I used this command to get all the date in every line:
cat sample_file.txt | grep "," | while read line
do
l_start_date=`echo $line|cut -d ',' -f4`
l_end_date=`echo $line|cut -d ',' -f5`
l_order_date=`echo $line|cut -d ',' -f8`
echo $l_start_date
echo $l_end_date
echo $l_order_date
done
Output:
Oct 7 2019 4:45 AM
Oct 7 2019 4:45 AM
Oct 6 2019 12:00 AM
Oct 17 2019 4:02 AM
Oct 17 2019 4:02 AM
Oct 16 2019 12:00 AM
expected output:
FROM: Oct 7 2019 6:32 AM
To: Oct 07 2019 6:32 AM
I used this sed command but it add also to 2 number day (17)
sed command sed 's|,Oct |,Oct 0|g' sample_file.txt
Oct 17 was change to Oct 017
upctm,pmdw_bip,pmdw_bip_mnt_35-FOLDistAutoRpt,Oct 07 2019 4:45 AM,Oct 07 2019 4:45 AM,1,1,Oct 06 2019 12:00 AM,Ended OK,3ppnc
upctm,pmdw_ddm,pmdw_ddm_dum_01-StartProjDCSDemand,Oct 017 2019 4:02 AM,Oct 017 2019 4:02 AM,3,1,Oct 016 2019 12:00 AM,Ended OK,3pqgq
I wish it was easier, but I only managed the following:
awk.f:
function fmt(s) {
split(s,a," "); a[2]=substr(a[2]+100,2)
return a[1] " " a[2] " "a[3] " " a[4] " " a[5]
}
BEGIN {FS=",";OFS=","}
{gsub(/ +/," ");
$4=fmt($4); $5=fmt($5); $8=fmt($8);
print}
This is a little awk script that first removes superfluous blanks and then picks out particular columns (4,5 and 8) and reformats the second part of each date string into a two-digit number.
You run the script like this:
awk -f f.awk sample_file.txt
output:
upctm,pmdw_aud,pmdw_aud_ext_06-GAPAnalysYTD,Oct 07 2019 6:32 AM,Oct 07 2019 6:32 AM,17,17,Oct 06 2019 12:00 AM,Ended OK,3pu9v
upctm,pmdw_ddm,pmdw_ddm_dum_01-StartProjDCSDemand,Oct 07 2019 4:02 AM,Oct 07 2019 4:02 AM,3,1,Oct 06 2019 12:00 AM,Ended OK,3pqgq
upctm,pmdw_bip,pmdw_bip_mnt_35-FOLDistAutoRpt,Oct 07 2019 4:45 AM,Oct 07 2019 4:45 AM,1,1,Oct 06 2019 12:00 AM,Ended OK,3ppnc
With a fixed locale, you can make a fixed replacement like
sed -r 's/(Jan|Feb|Oct|Whatever) ([1-9]) /\1 0\2 /g' sample_file.txt

rrule to get the 2nd Monday, Wednesday and Friday of the month, for every month

I am trying to create a rrule for my fullcalendar event, that occur on the 2nd Monday, Wednesday and Friday of the month for every month.
Here is the rrule I have tried
RRULE:FREQ=MONTHLY;COUNT=10;INTERVAL=1;WKST=SU;BYDAY=MO,WE,FR;BYSETPOS=2
events: [{
title: 'rrule event',
rrule: {
freq: RRule.MONTHLY,
count: 10,
interval: 1,
wkst: RRule.SU,
byweekday: [RRule.MO, RRule.WE, RRule.FR],
bysetpos: [2]
},
duration: '02:00',
rendering: 'inverse-background'
}
],
This is what I get
1 Fri, 03 May 2019 12:33:53 GMT
2 Wed, 05 Jun 2019 12:33:53 GMT
3 Wed, 03 Jul 2019 12:33:53 GMT
4 Mon, 05 Aug 2019 12:33:53 GMT
5 Wed, 04 Sep 2019 12:33:53 GMT
6 Fri, 04 Oct 2019 12:33:53 GMT
7 Mon, 04 Nov 2019 12:33:53 GMT
8 Wed, 04 Dec 2019 12:33:53 GMT
9 Fri, 03 Jan 2020 12:33:53 GMT
10 Wed, 05 Feb 2020 12:33:53 GMT
What is expected is
1 Mon, 08 Apr 2019
2 Wed, 10 Apr 2019
3 Fri, 12 Apr 2019
4 Mon, 13 May 2019
5 Wed, 08 May 2019
6 Fri, 10 May 2019.........
RFC 5545, section 3.3.10. states:
Each BYDAY value can also be preceded by a positive (+n) or
negative (-n) integer. If present, this indicates the nth
occurrence of a specific day within the MONTHLY or YEARLY "RRULE".
So the rule you're looking for literally specifies the 2nd Monday (2MO), Wednesday (2WE) and Friday (2FR) of each month.
FREQ=MONTHLY;COUNT=10;BYDAY=2MO,2WE,2FR
(click to see the results)
Note that INTERVAL=1 is the default and WKST=SU is meaningless in this case, so you can just as well omit them.
Btw, your rule basically says, of all Mondays, Wednesdays and Fridays of a month, take the second instance in that month.

ggplot geom_area failing

using the data below, and the line of code below, I am trying to produce a stacked area plot showing planned spend by project across the quarters specified in the data. Capex on the Y axis, quarters on the X axis. I have looked at many examples here and elsewhere, and I just cannot understand why it is failing. I'd like to post a screenshot of the result - but cant see a way to do that. Basically, it has the legend, and the axes look correct. But the main area of the chart is simply a grey grid, empty.
Code:
ggplot(short, aes(x=Quarter,y=Capex, fill=ProjectName, )) + geom_area(position = "stack") + ylim (1, 100000)
data:
ProjectName Quarter Capex
a F01 Jul 41709
a F02 Aug 41696
a F03 Sep 41667
a F04 Oct 41712
a F05 Nov 41676
a F06 Dec 41674
a F07 Jan 41694
a F08 Feb 41693
a F09 Mar 41698
a F10 Apr 41710
a F11 May 41694
a F12 Jun 41671
b F01 Jul 265197
b F02 Aug 265200
b F03 Sep 265187
b F04 Oct 265190
b F05 Nov 265179
b F06 Dec 265170
b F07 Jan 265167
b F08 Feb 265174
b F09 Mar 265187
b F10 Apr 265169
b F11 May 265186
b F12 Jun 265208
c F01 Jul 233335
c F02 Aug 233352
c F03 Sep 233344
c F04 Oct 233344
c F05 Nov 233344
c F06 Dec 233350
c F07 Jan 32
c F08 Feb 31
c F09 Mar 23
c F10 Apr 5046
c F11 May 5005
c F12 Jun 50
d F01 Jul 40
d F02 Aug 43
d F03 Sep 30
d F04 Oct 5038
d F05 Nov 45
d F06 Dec 8
d F07 Jan 45
d F08 Feb 20034
d F09 Mar 40
d F10 Apr 40
d F11 May 2
d F12 Jun 500045
e F01 Jul 300011
I'm pretty sure you want a stacked bar chart, not an area chart? Is this what you're after?
ggplot(short, aes(x=Quarter,y=Capex, fill=ProjectName, )) +
geom_bar(stat = "identity")
I'm not sure why you've got those y axis limits, they cut off your data, but this should be done with scale_y_continuous(limits = c(min, max)).
As a note, it's better to use the output from dput(data) when sharing your data, as it brings the structure of the data along with it. Have a look at How to make a great R reproducible example?

Resources