systemd script for notify-send fails with error "The connection is closed" - systemd

I am trying to run a systemd timer. I am posting all the relevant files and the error below. I have posted the nodejs file but I tried with a simple shell script as well as explained in the Edit section.
/usr/bin/systemd/system/notification.service
[Unit]
Description=Show notification
After=systemd-user-sessions.service,systemd-journald.service
Wants=notification.timer
[Service]
Type=simple
ExecStart=/usr/bin/node /home/rounak/base/scripts/get-combined-notification.js
Environment="DISPLAY=:0" "XAUTHORITY=/home/rounak/.Xauthority" "DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus"
[Install]
WantedBy=multi-user.target
/usr/bin/systemd/system/notification.timer
[Unit]
Description=Show notification
[Timer]
OnUnitActiveSec=1m
[Install]
WantedBy=timers.target
get-combined-notification.js
const util = require("util");
const stdExec = require("child_process").exec;
const exec = util.promisify(stdExec);
const appNameForDunst = "CombinedNotification";
const executeScript = async (shellCommand) => {
return await exec(shellCommand);
};
const notifySendCommand = async (text) =>
await executeScript(
`notify-send -t 5000 -a ${appNameForDunst} " " ${JSON.stringify(
text
)}`
);
const commands = [
{
title: "Battery",
command: "acpi -b",
process: 'return output.split(",")[1]',
},
{
title: "Network",
command: "nmcli -t -f NAME connection show --active",
process: "return output",
},
{
title: "Workspace",
command: "xprop -root _NET_CURRENT_DESKTOP",
process:
'return ["view", "dev", "servers", "config", "notes", "av"][output.trim().substr(-1)]',
},
{
title: "Date",
command: "date '+ %a %d %b %y%nTime: %I:%M'",
process: "return output",
},
{
title: "Window Count",
command: "xprop -root _NET_CLIENT_LIST_STACKING",
process: 'return output.split("#").join("").split(",").length',
},
];
let final = "";
const handler = async (command, index) => {
const result = await executeScript(command.command);
const processOutput = new Function("output", command.process);
final = final + `${command.title}: ${processOutput(result.stdout)}\n`;
};
const main = async () => {
await Promise.allSettled(commands.map(handler));
notifySendCommand(final);
};
main()
journalctl -u notification
Jul 15 18:31:03 rounak node[3215]: Node.js v18.3.0
Jul 15 18:31:03 rounak systemd[1]: notification.service: Main process exited, code=exited, status=1/FAI>
Jul 15 18:31:03 rounak systemd[1]: notification.service: Failed with result 'exit-code'.
Jul 15 18:33:03 rounak systemd[1]: Started Show notification.
Jul 15 18:33:03 rounak node[4229]: node:internal/errors:845
Jul 15 18:33:03 rounak node[4229]: const err = new Error(message);
Jul 15 18:33:03 rounak node[4229]: ^
Jul 15 18:33:03 rounak node[4229]: Error: Command failed: notify-send -t 5000 -a CombinedNotification ">
Jul 15 18:33:03 rounak node[4229]: The connection is closed
Jul 15 18:33:03 rounak node[4229]: at ChildProcess.exithandler (node:child_process:387:12)
Jul 15 18:33:03 rounak node[4229]: at ChildProcess.emit (node:events:527:28)
Jul 15 18:33:03 rounak node[4229]: at maybeClose (node:internal/child_process:1090:16)
Jul 15 18:33:03 rounak node[4229]: at ChildProcess._handle.onexit (node:internal/child_process:302:>
Jul 15 18:33:03 rounak node[4229]: code: 1,
Jul 15 18:33:03 rounak node[4229]: killed: false,
Jul 15 18:33:03 rounak node[4229]: signal: null,
Jul 15 18:33:03 rounak node[4229]: cmd: 'notify-send -t 5000 -a CombinedNotification " " "Date: Fri >
Jul 15 18:33:03 rounak node[4229]: stdout: '',
Jul 15 18:33:03 rounak node[4229]: stderr: 'The connection is closed\n'
Jul 15 18:33:03 rounak node[4229]: }
Edit:
To rule out nodejs as the culprit, I used a shell script with one line notify-send "some" "some" instead of the nodejs script. I get the same error in journal: sh[2607]: The connection is closed

Related

Can't start elasticsearch service on centos 7

I just install the elasticsearch but when I try to start is not work. Anyone have any idea what I can do?
sudo journalctl --unit elasticsearch
-- Logs begin at Sat 2020-08-29 09:54:58 UTC, end at Sat 2020-08-29 13:15:35 UTC. --
Aug 29 10:10:28 meriadoc.dallas-idc.com systemd[1]: Starting Elasticsearch...
Aug 29 10:10:35 meriadoc.dallas-idc.com systemd-entrypoint[3579]: fatal error in thread [main], exiting
Aug 29 10:10:35 meriadoc.dallas-idc.com systemd-entrypoint[3579]: java.lang.NoClassDefFoundError: Could not initialize class com.sun.jna.Native
Aug 29 10:10:35 meriadoc.dallas-idc.com systemd-entrypoint[3579]: at org.elasticsearch.systemd.Libsystemd.lambda$static$0(Libsystemd.java:34)
Aug 29 10:10:35 meriadoc.dallas-idc.com systemd-entrypoint[3579]: at java.base/java.security.AccessController.doPrivileged(AccessController.java:312)
Aug 29 10:10:35 meriadoc.dallas-idc.com systemd-entrypoint[3579]: at org.elasticsearch.systemd.Libsystemd.<clinit>(Libsystemd.java:33)
Aug 29 10:10:35 meriadoc.dallas-idc.com systemd-entrypoint[3579]: at org.elasticsearch.systemd.SystemdPlugin.sd_notify(SystemdPlugin.java:126)
Aug 29 10:10:35 meriadoc.dallas-idc.com systemd-entrypoint[3579]: at org.elasticsearch.systemd.SystemdPlugin.onNodeStarted(SystemdPlugin.java:137)
Aug 29 10:10:35 meriadoc.dallas-idc.com systemd-entrypoint[3579]: at java.base/java.util.ArrayList.forEach(ArrayList.java:1510)
Aug 29 10:10:35 meriadoc.dallas-idc.com systemd-entrypoint[3579]: at org.elasticsearch.node.Node.start(Node.java:868)
Aug 29 10:10:35 meriadoc.dallas-idc.com systemd-entrypoint[3579]: at org.elasticsearch.bootstrap.Bootstrap.start(Bootstrap.java:317)
Aug 29 10:10:35 meriadoc.dallas-idc.com systemd-entrypoint[3579]: at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:402)
Aug 29 10:10:35 meriadoc.dallas-idc.com systemd-entrypoint[3579]: at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:170)
Aug 29 10:10:35 meriadoc.dallas-idc.com systemd-entrypoint[3579]: at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:161)
Aug 29 10:10:35 meriadoc.dallas-idc.com systemd-entrypoint[3579]: at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:86)
Aug 29 10:10:35 meriadoc.dallas-idc.com systemd-entrypoint[3579]: at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:127)
Aug 29 10:10:35 meriadoc.dallas-idc.com systemd-entrypoint[3579]: at org.elasticsearch.cli.Command.main(Command.java:90)
Aug 29 10:10:35 meriadoc.dallas-idc.com systemd-entrypoint[3579]: at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:126)
Aug 29 10:10:35 meriadoc.dallas-idc.com systemd-entrypoint[3579]: at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:92)
Aug 29 10:10:35 meriadoc.dallas-idc.com systemd[1]: elasticsearch.service: main process exited, code=exited, status=1/FAILURE
Aug 29 10:10:35 meriadoc.dallas-idc.com systemd[1]: Failed to start Elasticsearch.
Aug 29 10:10:35 meriadoc.dallas-idc.com systemd[1]: Unit elasticsearch.service entered failed state.
Thank you so much
If you notice carefully the error message in startup logs, which seems to cause the startup failure.
Aug 29 10:10:35 meriadoc.dallas-idc.com systemd-entrypoint[3579]:
java.lang.NoClassDefFoundError: Could not initialize class
com.sun.jna.Native
Please follow the https://www.jetbrains.com/help/upsource/error-could-not-initialize-class-com-sun-jna-native.html#8182b, which explained in detail the cause of the error and 2 ways to resolve that.

run ruby script at login xfce

I'm using manjaro and I want to run a ruby script after login.
Here's my script:
def get_line(filename, lineno)
File.open(filename,'r') do |f|
f.gets until f.lineno == lineno - 1
f.gets
end
end
filename = "list.md"
filepath = File.join(File.dirname(__FILE__), filename)
count = %x{cat #{filepath} | sed '/^\s*$/d' | wc -l }.to_i
random_element = rand((1..count))
line = get_line(filepath, random_element)
options = { :address => "smtp.gmail.com",
:port => 587,
:user_name => 'xxxx#gmail.com',
:password => 'xxxxx',
:authentication => 'plain',
:enable_starttls_auto => true }
Mail.defaults do
delivery_method :smtp, options
end
Mail.deliver do
to 'xxxxx#gmail.com'
from 'xxxxxx#gmail.com'
subject 'Test'
body "#{line}"
end
I tried /etc/profile.d, .bash_profile and as a service at /etc/systemd/system
[Unit]
Description=Example systemd service.
[Service]
Type=simple
ExecStart=/usr/bin/ruby /home/dnl/Documents/git/send_mail_reminders/send_mail.rb
[Install]
WantedBy=multi-user.target
I did service start, status, enable and then reboot.
Output from service status
● autostart.service - Example systemd service.
Loaded: loaded (/etc/systemd/system/autostart.service; enabled; vendor preset: disabled)
Active: failed (Result: exit-code) since Sun 2020-08-16 13:28:10 CEST; 5min ago
Process: 439 ExecStart=/usr/bin/ruby /home/dnl/Documents/git/send_mail_reminders/send_mail.rb (code=exited, status=1/FAILURE)
Main PID: 439 (code=exited, status=1/FAILURE)
Aug 16 13:28:10 dnl ruby[439]: from /usr/lib/ruby/2.7.0/net/smtp.rb:548:in `do_start'
Aug 16 13:28:10 dnl ruby[439]: from /usr/lib/ruby/2.7.0/net/smtp.rb:518:in `start'
Aug 16 13:28:10 dnl ruby[439]: from /usr/lib/ruby/gems/2.7.0/gems/mail-2.7.1/lib/mail/network/delivery_methods/smtp.rb:109:in `start_smtp_session'
Aug 16 13:28:10 dnl ruby[439]: from /usr/lib/ruby/gems/2.7.0/gems/mail-2.7.1/lib/mail/network/delivery_methods/smtp.rb:100:in `deliver!'
Aug 16 13:28:10 dnl ruby[439]: from /usr/lib/ruby/gems/2.7.0/gems/mail-2.7.1/lib/mail/message.rb:2159:in `do_delivery'
Aug 16 13:28:10 dnl ruby[439]: from /usr/lib/ruby/gems/2.7.0/gems/mail-2.7.1/lib/mail/message.rb:262:in `deliver'
Aug 16 13:28:10 dnl ruby[439]: from /usr/lib/ruby/gems/2.7.0/gems/mail-2.7.1/lib/mail/mail.rb:133:in `deliver'
Aug 16 13:28:10 dnl ruby[439]: from /home/dnl/Documents/git/send_mail_reminders/send_mail.rb:30:in `<main>'
Aug 16 13:28:10 dnl systemd[1]: autostart.service: Main process exited, code=exited, status=1/FAILURE
Aug 16 13:28:10 dnl systemd[1]: autostart.service: Failed with result 'exit-code'.
Is there any problem with my ruby code?
According to the line number of produced error there's timeout when opening network socket, so it seems network isn't ready when your service is running. Try this [Unit] section so the service will start after network is initialized:
[Unit]
Description=Example systemd service.
Requires=network-online.target
After=network-online.target

How can I get AWK to start reading by the end?

I need to parse all a file into a better format to produce an outcome with columns delimited by a comma, thinking of being able to export the content in CSV file.
This is an example of my input;
. D 0 Mon Dec 10 11:07:46 2018
.. D 0 Mon Feb 19 11:38:06 2018
RJ9-5 D 0 Fri Nov 30 10:34:24 2018
WorkingOnClass D 0 Wed Feb 28 09:37:52 2018
ML-Test001 D 0 Fri Dec 7 16:38:56 2018
TestML4Testing D 0 Wed Aug 22 08:58:42 2018
ML-NewDataSE SetCases1.xlsx A 1415577 Wed Aug 29 14:00:16 2018
DR0001-Dum01 D 0 Thu Aug 16 08:24:25 2018
DR0002-Dum02 D 0 Thu Aug 16 09:04:50 2018
Readme File for Documentation And Data Description.docx A 16136 Wed Aug 29 14:00:24 2018
ML Database Prototype D 0 Thu Dec 6 15:11:11 2018
OneNote D 0 Mon Dec 3 09:39:20 2018
Data A 0 Mon Dec 10 11:07:46 2018
\RJ9-5
. D 0 Fri Nov 30 10:34:24 2018
.. D 0 Mon Dec 10 11:07:46 2018
KLR0151_Set023_Files_RJ9_05.xlsx A 182462 Wed Apr 4 02:48:55 2018
KLR0152_Set023_Files_RJ9_05.xlsx A 525309 Wed Apr 4 02:53:57 2018
\ML-Test001
. D 0 Wed Feb 28 09:37:52 2018
.. D 0 Mon Dec 10 11:07:46 2018
WT_Conforming_Format1_1.docx A 500914 Mon Feb 26 08:50:55 2018
Conforming_Format_1_1.xlsx A 130647 Mon Feb 26 08:52:33 2018
DR0135_Dum01_text.xls A 974848 Mon Feb 12 08:11:11 2018
DR0139_Dum02_body.xls A 1061888 Tue Jun 19 13:43:54 2018
DataSet_File_mod0874953.xlsx A 149835 Mon Feb 26 14:17:02 2018
File Path For Dataset-2018.07.11.xlsx A 34661 Mon Feb 12 09:27:17
This is script right here can make the job:
#!/bin/bash
awk -v OFS=, '
BEGIN { print "PATH, FILENAME, SIZE, TIMESTAMP" }
/[\\]/ { path=$0 }
$2 ~ /A/ {print path"\\"$1,$3,$4 " " $5 " " $6 " " $7 " "$8 }
' "$#"
But is ignoring the names with spaces on it, so I need to validate them with something like:
awk -v FS="\t" '{print $1}'
But I could't integrate into the shell script, because the way the shell script is working, so I was thinking on make AWK to start reading by the end, since the end is always the same, and leave the rest.
The output should something like this:
/RJ9-5/KLR0151_Set023_Files_RJ9_05.xlsx,182462,Wed Apr 4 02:48:55 2018
/RJ9-5/KLR0152_Set023_Files_RJ9_05.xlsx,25309,Wed Apr 4 02:53:57 2018
/ML-Test001/WT_Conforming_Format1_1.docx,500914,Mon Feb 26 08:50:55 2018
/ML-Test001/Format_1_1.xlsx,130647,Mon Feb 26 08:52:33 2018
/ML-Test001/DR0135_Dum01_text.xls,974848,Mon Feb 12 08:11:11 2018
/ML-Test001/DR0139_Dum02_body.xls,1061888,Tue Jun 19 13:43:54 2018
/ML-Test001/DataSet_File_mod0874953.xlsx,149835,Mon Feb 26 14:17:02 2018
/ML-Test001/File Path For Dataset-2018.07.11.xlsx,34661,Mon Feb 12 09:27:17 2018
With GNU awk for the 3rd arg to match() (and far less importantly \s shorthand for [[:space:]]):
$ cat tst.awk
BEGIN { OFS="," }
{ gsub(/^\s+|\s+$/,"") }
sub(/^\\/,"/") { path = $0; next }
path == "" { next }
match($0,/^(.*[^ ]) +A +([^ ]+) +(.*)/,a) { print path "/" a[1], a[2], a[3] }
$ awk -f tst.awk file
/RJ9-5/KLR0151_Set023_Files_RJ9_05.xlsx,182462,Wed Apr 4 02:48:55 2018
/RJ9-5/KLR0152_Set023_Files_RJ9_05.xlsx,525309,Wed Apr 4 02:53:57 2018
/ML-Test001/WT_Conforming_Format1_1.docx,500914,Mon Feb 26 08:50:55 2018
/ML-Test001/Conforming_Format_1_1.xlsx,130647,Mon Feb 26 08:52:33 2018
/ML-Test001/DR0135_Dum01_text.xls,974848,Mon Feb 12 08:11:11 2018
/ML-Test001/DR0139_Dum02_body.xls,1061888,Tue Jun 19 13:43:54 2018
/ML-Test001/DataSet_File_mod0874953.xlsx,149835,Mon Feb 26 14:17:02 2018
/ML-Test001/File Path For Dataset-2018.07.11.xlsx,34661,Mon Feb 12 09:27:17
Try this Perl solution:
$ perl -lane ' if(/^\s*$/) { $x=0;$y=0} if(/^\\/) {$x=1 ;($a=$_)=~s/\s*$//g;$a=~s/\\/\//g; } $y++ if $x==1 ; if($y>3) { s/^\s*//g; $_=~s/(.+?)\s+\S+\s+((\d+)\s+.+)/$1 $2/g;print "$a/$_" } ' essparaq.txt
/RJ9-5/KLR0151_Set023_Files_RJ9_05.xlsx 182462 Wed Apr 4 02:48:55 2018
/RJ9-5/KLR0152_Set023_Files_RJ9_05.xlsx 525309 Wed Apr 4 02:53:57 2018
/ML-Test001/WT_Conforming_Format1_1.docx 500914 Mon Feb 26 08:50:55 2018
/ML-Test001/Conforming_Format_1_1.xlsx 130647 Mon Feb 26 08:52:33 2018
/ML-Test001/DR0135_Dum01_text.xls 974848 Mon Feb 12 08:11:11 2018
/ML-Test001/DR0139_Dum02_body.xls 1061888 Tue Jun 19 13:43:54 2018
/ML-Test001/DataSet_File_mod0874953.xlsx 149835 Mon Feb 26 14:17:02 2018
/ML-Test001/File Path For Dataset-2018.07.11.xlsx 34661 Mon Feb 12 09:27:17
$ cat essparaq.txt
. D 0 Mon Dec 10 11:07:46 2018
.. D 0 Mon Feb 19 11:38:06 2018
RJ9-5 D 0 Fri Nov 30 10:34:24 2018
WorkingOnClass D 0 Wed Feb 28 09:37:52 2018
ML-Test001 D 0 Fri Dec 7 16:38:56 2018
TestML4Testing D 0 Wed Aug 22 08:58:42 2018
ML-NewDataSE SetCases1.xlsx A 1415577 Wed Aug 29 14:00:16 2018
DR0001-Dum01 D 0 Thu Aug 16 08:24:25 2018
DR0002-Dum02 D 0 Thu Aug 16 09:04:50 2018
Readme File for Documentation And Data Description.docx A 16136 Wed Aug 29 14 :00:24 2018
ML Database Prototype D 0 Thu Dec 6 15:11:11 2018
OneNote D 0 Mon Dec 3 09:39:20 2018
Data A 0 Mon Dec 10 11:07:46 2018
\RJ9-5
. D 0 Fri Nov 30 10:34:24 2018
.. D 0 Mon Dec 10 11:07:46 2018
KLR0151_Set023_Files_RJ9_05.xlsx A 182462 Wed Apr 4 02:48:55 2018
KLR0152_Set023_Files_RJ9_05.xlsx A 525309 Wed Apr 4 02:53:57 2018
\ML-Test001
. D 0 Wed Feb 28 09:37:52 2018
.. D 0 Mon Dec 10 11:07:46 2018
WT_Conforming_Format1_1.docx A 500914 Mon Feb 26 08:50:55 2018
Conforming_Format_1_1.xlsx A 130647 Mon Feb 26 08:52:33 2018
DR0135_Dum01_text.xls A 974848 Mon Feb 12 08:11:11 2018
DR0139_Dum02_body.xls A 1061888 Tue Jun 19 13:43:54 2018
DataSet_File_mod0874953.xlsx A 149835 Mon Feb 26 14:17:02 2018
File Path For Dataset-2018.07.11.xlsx A 34661 Mon Feb 12 09:27:17

Need to take only one entry pertaining to particular name as in first column and iterate over the file

I have a file called Files1 which has below data, where i Need to take only the line (entire line) which has all the column entries (ie $1...to ..$12) and iterate over the file..
example: for name "testvnc02" it should only print below line as it has all the fields of its name and ignore rest of the line and take another name and do the same.
testvnc02 out: anders pts/83 192.168.87.1 Mon Feb 20
00:31 - 01:04 00:33
[testvnc02 ] out:
[testvnc02 ] out:
[testvnc02 ] out:
testvnc02 out:
testvnc02 out: anders pts/83 192.168.87.1 Mon Feb 20 00:31 - 01:04 00:33
testvnc02 out: curtist pts/1927 192.202.45.84 Thu Feb 9 17:54 - 19:55 02:00
testvnc02 out: curtist pts/1928 :32.0 Thu Feb 9 17:56 still logged in
testvnc02 out: echolu pts/82 :13 Tue Feb 14 01:07 still logged in
testvnc02 out: echolu pts/83 :13.0 Tue Feb 14 01:08 - 01:23 3+00:14
testvnc02 out: garimas pts/71 test-garimas.caden Fri Feb 17 02:22 - 03:23 01:01
testvnc02 out: garimas pts/71 test-garimas.caden Sun Feb 12 22:54 - 00:04 01:09
testvnc02 out: garimas pts/83 test-garimas.caden Mon Feb 20 01:39 - 02:39 01:00
testvnc02 out: garimas pts/84 test-garimas.caden Tue Feb 14 04:46 - 05:48 01:01
testvnc02 out: hjyu pts/87 testvnc02:28.0 Wed Feb 8 16:30 still logged in
testvnc02 out: hongshaw pts/17 192.168.222.27 Tue Feb 7 21:39 - 03:52 06:13
testvnc02 out: npitla pts/4 :4.0 Fri Feb 192 00:55 - 07:30 2+06:35
testvnc02 out: npitla pts/4 :4.0 Sun Feb 12 07:30 - 22:54 3+15:24
testvnc02 out: npitla pts/4 :4.0 Tue Feb 7 21:36 - 00:55 2+03:18
testvnc02 out: npitla pts/71 :4.0 Fri Feb 192 02:49 - 03:36 00:47
testvnc02 out: npitla pts/71 :4.0 Mon Feb 13 09:58 - 22:54 2+12:55
testvnc02 out: npitla pts/71 :4.0 Sun Feb 12 07:21 - 07:25 00:03
testvnc02 out: npitla pts/71 :4.0 Tue Feb 7 22:20 - 01:30 2+03:192
testvnc02 out: npitla pts/81 :4.0 Fri Feb 192 03:24 - 03:36 00:12
testvnc02 out: npitla pts/81 :4.0 Mon Feb 13 192:02 - 22:53 2+12:51
testvnc02 out: npitla pts/81 :4.0 Tue Feb 7 22:21 - 01:30 2+03:09
testvnc02 out: npitla pts/84 :4.0 Fri Feb 192 03:32 - 03:36 00:03
testvnc02 out: npitla pts/84 :4.0 Wed Feb 8 09:24 - 00:54 1+15:30
testvnc02 out: pedro pts/89 testvcut07.perence Wed Feb 15 01:41 - 01:50 00:09
testvnc02 out: pedro pts/89 testvcut07.perence Wed Feb 15 01:52 - 01:55 00:02
testvnc02 out: ruizh pts/89 szlnx4.perence.c Wed Feb 15 21:09 - 21:55 3+00:46
testvnc02 out: sbrahma pts/71 test-sbrahma.caden Fri Feb 17 14:46 - 14:53 00:06
testvnc02 out: sonamt pts/85 test-sonamt.caden Wed Feb 8 22:21 - 23:41 01:19
testvnc02 out: sungsikh pts/1927 :29.0 Thu Feb 9 16:13 - 16:19 00:06
testvnc02 out: sungsikh pts/4 :29.0 Thu Feb 16 12:55 still logged in
testvnc02 out: tao1wang pts/1920 :31 Thu Feb 9 192:19 still logged in
testvnc02 out: tao1wang pts/1921 :31 Thu Feb 9 192:19 still logged in
testvnc02 out: tao1wang pts/1922 :31 Thu Feb 9 192:20 still logged in
testvnc02 out: tao1wang pts/1923 :31 Thu Feb 9 192:20 still logged in
testvnc02 out: tao1wang pts/1924 :31 Thu Feb 9 192:20 still logged in
testvnc02 out: tao1wang pts/1925 :31 Thu Feb 9 192:21 still logged in
testvnc02 out: tao1wang pts/85 192.168.12.43 Thu Feb 9 08:59 - 09:22 00:23
testvnc02 out: tao1wang pts/85 :31 Thu Feb 9 192:17 still logged in
testvnc02 out: tao1wang pts/90 :31 Thu Feb 9 09:00 still logged in
testvnc02 out: tao1wang pts/91 :31 Thu Feb 9 09:00 still logged in
testvnc02 out: tao1wang pts/92 :31 Thu Feb 9 09:00 still logged in
testvnc02 out: tao1wang pts/93 :31 Thu Feb 9 09:00 still logged in
testvnc02 out: tao1wang pts/94 :31 Thu Feb 9 09:00 still logged in
testvnc02 out: tao1wang pts/95 :31 Thu Feb 9 09:00 still logged in
testvnc02 out: tao1wang pts/96 :31 Thu Feb 9 09:00 still logged in
testvnc02 out: tao1wang pts/97 :31 Thu Feb 9 09:00 still logged in
testvnc02 out: tao1wang pts/98 :31 Thu Feb 9 192:18 still logged in
testvnc02 out: tao1wang pts/99 :31 Thu Feb 9 192:18 still logged in
testvnc02 out: vsanjay pts/71 :12 Sun Feb 19 23:06 still logged in
testvnc02 out: vsanjay pts/81 :12 Sun Feb 19 23:06 still logged in
testvnc02 out: vsanjay pts/88 :12 Wed Feb 15 01:30 still logged in
testvnc02 out: yulizhu pts/0 :14.0 Wed Feb 8 09:192 - 11:50 02:40
testvnc02 out: yulizhu pts/0 :14.0 Wed Feb 8 11:50 - 12:192 00:19
testvnc02 out: yulizhu pts/1926 :14.0 Thu Feb 9 11:04 - 17:38 5+06:33
testvnc02 out: yulizhu pts/17 :14.0 Wed Feb 8 09:11 - 09:12 00:01
testvnc02 out: yulizhu pts/58 :14.0 Wed Feb 8 09:13 - 11:49 02:36
testvnc02 out: yulizhu pts/71 :14.0 Fri Feb 192 12:50 - 12:52 00:01
testvnc02 out: yulizhu pts/71 :14.0 Fri Feb 192 13:25 - 13:27 00:02
testvnc02 out: yulizhu pts/84 :14.0 Tue Feb 14 17:38 - 19:11 01:33
testvnc02 out: yulizhu pts/84 :14.0 Tue Feb 14 19:18 still logged in
testvnc02 out: yulizhu pts/85 :14.0 Wed Feb 8 11:49 - 16:20 04:31
testvnc02 out: yulizhu pts/85 :14.0 Wed Feb 8 16:20 - 18:31 02:192
testvnc02 out: yulizhu pts/87 :14.0 Wed Feb 8 12:12 - 14:20 02:08
testvnc02 out: yulizhu pts/87 :14.0 Wed Feb 8 14:20 - 16:20 01:59
testvnc02 out: yulizhu pts/88 :14.0 Thu Feb 9 11:46 - 22:05 192:19
testvnc02 out: yulizhu pts/88 :14.0 Tue Feb 14 18:21 - 19:26 01:04
testvnc02 out: yulizhu pts/88 :14.0 Wed Feb 8 16:03 - 16:192 00:07
testvnc02 out: yulizhu pts/88 :14.0 Wed Feb 8 16:19 - 16:20 00:01
testvnc02 out: yulizhu pts/88 :14.0 Wed Feb 8 17:12 - 11:04 17:52
testvnc02 out: yulizhu pts/89 :14.0 Wed Feb 8 18:27 - 17:38 5+23:11
[testvnc04] out:
[testvnc04] out:
testvnc04 out: amitv pts/22 textnntv.cadenc Mon Feb 20 02:14 - 03:14 01:00
testvnc04 out: amitv pts/27 textnntv.cadenc Sun Feb 12 20:55 - 21:56 01:00
testvnc04 out: amitv pts/50 textnntv.cadenc Thu Feb 16 09:29 - 192:29 01:00
testvnc04 out: amitv pts/50 textnntv.cadenc Tue Feb 14 21:55 - 22:55 01:00
testvnc04 out: amyluo pts/22 192.16833.221.89 Sun Feb 19 21:42 - 22:53 01:192
testvnc04 out: amyluo pts/23 :3.0 Sun Feb 19 21:43 still logged in
testvnc04 out: amyluo pts/24 :3.0 Sun Feb 19 21:43 still logged in
testvnc04 out: amyluo pts/25 :3.0 Sun Feb 19 21:43 still logged in
testvnc04 out: amyluo pts/26 :3.0 Sun Feb 12 01:01 - 21:41 7+20:39
testvnc04 out: amyluo pts/26 :3.0 Sun Feb 19 21:43 still logged in
testvnc04 out: amyluo pts/56 192.16833.221.89 Sun Feb 19 21:40 - 21:41 00:01
testvnc04 out: amyluo pts/56 :3.0 Sun Feb 19 21:43 still logged in
testvnc04 out: amyluo pts/57 :3.0 Sun Feb 19 21:43 still logged in
testvnc04 out: dclor pts/27 192.202.45.91 Sun Feb 12 16:42 - 17:43 01:00
testvnc04 out: dclor pts/28 :4 Sun Feb 12 16:43 still logged in
testvnc04 out: dclor pts/29 :4 Sun Feb 12 16:43 still logged in
testvnc04 out: dclor pts/49 :4 Mon Feb 13 17:13 still logged in
testvnc04 out: dclor pts/51 :4 Tue Feb 14 08:32 still logged in
testvnc04 out: dclor pts/9 :4 Mon Feb 20 13:28 still logged in
testvnc04 out: horeftis pts/48 test-horeftis.cade Mon Feb 13 14:42 - 14:44 00:01
testvnc04 out: jinyi pts/27 192.16833.2192.16828 Sun Feb 12 18:36 - 18:44 00:07
testvnc04 out: jinyi pts/30 :5.0 Sun Feb 12 18:40 still logged in
testvnc04 out: joao pts/22 test-joao.perence. Mon Feb 20 04:57 still logged in
testvnc04 out: joao pts/9 :52.0 Tue Feb 14 04:29 - 06:15 01:45
testvnc04 out: joao pts/9 :52.0 Tue Feb 14 06:15 - 02:01 19:46
testvnc04 out: joao pts/9 :52.0 Wed Feb 15 02:01 - 04:58 5+02:56
testvnc04 out: jolinr pts/50 testfib240.perence Tue Feb 14 17:54 - 18:05 00:192
testvnc04 out: jolinr pts/52 :6.0 Tue Feb 14 17:56 still logged in
testvnc04 out: jolinr pts/53 :6 Tue Feb 14 17:56 still logged in
testvnc04 out: jolinr pts/56 :6 Thu Feb 16 18:08 - 18:44 00:36
testvnc04 out: jolinr pts/57 :6 Thu Feb 16 18:11 - 18:44 00:33
testvnc04 out: jolinr pts/58 :6 Thu Feb 16 18:20 - 18:44 00:23
testvnc04 out: jolinr pts/59 :6 Thu Feb 16 18:22 - 18:44 00:22
testvnc04 out: jxie pts/22 vm1lnx3.perence. Mon Feb 20 00:27 - 00:42 00:15
testvnc04 out: jxie pts/56 vm1lnx3.perence. Fri Feb 17 01:52 - 04:08 02:16
testvnc04 out: jxie pts/56 vm1lnx3.perence. Fri Feb 17 08:57 - 09:27 00:29
testvnc04 out: jxie pts/56 vm1lnx3.perence. Fri Feb 17 192:19 - 11:41 01:21
testvnc04 out: jxie pts/56 vm1lnx3.perence. Fri Feb 17 21:59 - 23:00 01:00
testvnc04 out: jxie pts/56 vm1lnx3.perence. Sat Feb 18 01:36 - 01:45 00:09
testvnc04 out: jxie pts/56 vm1lnx3.perence. Sat Feb 18 06:41 - 11:17 04:36
testvnc04 out: jxie pts/56 vm1lnx3.perence. Sun Feb 19 18:53 - 19:56 01:03
testvnc04 out: jxie pts/56 vm1lnx3.perence. Thu Feb 16 21:37 - 00:15 02:38
testvnc04 out: jxie pts/57 vm1lnx3.perence. Fri Feb 17 09:04 - 09:27 00:22
testvnc04 out: jxie pts/57 vm1lnx3.perence. Sat Feb 18 06:44 - 192:18 03:33
testvnc04 out: jxie pts/58 vm1lnx3.perence. Mon Feb 20 02:25 - 18:38 16:12
testvnc04 out: jxie pts/60 vm1lnx3.perence. Thu Feb 16 18:31 - 18:51 00:20
testvnc04 out: kitagawa pts/21 :48.0 Sun Feb 12 06:47 still logged in
testvnc04 out: kitagawa pts/27 :48.0 Mon Feb 13 01:12 still logged in
testvnc04 out: kitagawa pts/48 :48.0 Mon Feb 13 16:54 still logged in
testvnc04 out: kitagawa pts/50 cdtest135.perence. Wed Feb 15 01:48 - 02:48 01:00
testvnc04 out: kitagawa pts/54 :51.0 Thu Feb 16 15:32 still logged in
testvnc04 out: kitagawa pts/59 :48.0 Mon Feb 20 15:34 still logged in
testvnc04 out: kmchow pts/31 test-kmchow.cadenc Mon Feb 13 09:54 still logged in
testvnc04 out: kmchow pts/32 :99 Mon Feb 13 09:55 still logged in
testvnc04 out: kmchow pts/33 :99 Mon Feb 13 09:55 still logged in
testvnc04 out: kmchow pts/34 :99 Mon Feb 13 09:55 still logged in
testvnc04 out: kmchow pts/35 :99 Mon Feb 13 09:55 still logged in
testvnc04 out: kmchow pts/36 :99 Mon Feb 13 09:55 still logged in
testvnc04 out: kmchow pts/37 :99 Mon Feb 13 09:55 still logged in
testvnc04 out: kmchow pts/38 :99 Mon Feb 13 09:55 still logged in
testvnc04 out: kmchow pts/39 :99 Mon Feb 13 09:55 still logged in
testvnc04 out: kmchow pts/40 :70 Mon Feb 13 09:56 - 192:02 00:05
testvnc04 out: kmchow pts/40 :70 Mon Feb 13 192:02 still logged in
testvnc04 out: kmchow pts/41 :70 Mon Feb 13 09:56 - 192:02 00:05
testvnc04 out: kmchow pts/41 :70 Mon Feb 13 192:02 still logged in
testvnc04 out: kmchow pts/42 :70 Mon Feb 13 09:56 - 192:02 00:05
testvnc04 out: kmchow pts/42 :70 Mon Feb 13 192:02 still logged in
testvnc04 out: kmchow pts/43 :70 Mon Feb 13 09:56 - 192:02 00:05
testvnc04 out: kmchow pts/43 :70 Mon Feb 13 192:02 still logged in
testvnc04 out: kmchow pts/44 :70 Mon Feb 13 09:56 - 192:02 00:05
testvnc04 out: kmchow pts/44 :70 Mon Feb 13 192:02 still logged in
testvnc04 out: kmchow pts/45 :70 Mon Feb 13 09:56 - 192:02 00:05
testvnc04 out: kmchow pts/45 :70 Mon Feb 13 192:02 still logged in
testvnc04 out: kmchow pts/46 :70 Mon Feb 13 09:56 - 192:02 00:05
testvnc04 out: kmchow pts/46 :70 Mon Feb 13 192:02 still logged in
testvnc04 out: kmchow pts/47 :70 Mon Feb 13 09:56 - 192:02 00:05
testvnc04 out: kmchow pts/47 :70 Mon Feb 13 192:02 still logged in
testvnc04 out: kmchow pts/55 :70.0 Thu Feb 16 16:192 still logged in
testvnc04 out: sanubhav pts/56 test-sanubhav.cad Sun Feb 19 00:44 - 00:49 00:05
testvnc04 out: trr pts/50 fmf.perence. Mon Feb 13 22:32 - 14:16 15:43
testvnc04 out: trr pts/50 testvnc04:2.0 Thu Feb 16 14:37 still logged in
testvnc05 out:
testvnc05 out:
testvnc05 out: harman pts/169 :pts/338:S.0 Mon Feb 20 00:55 - 06:19 05:24
testvnc05 out: harman pts/270 :pts/331:S.0 Sun Feb 19 21:43 - 03:51 06:07
testvnc05 out: harman pts/271 :pts/331:S.2 Sun Feb 19 21:43 - 03:51 06:07
testvnc05 out: harman pts/291 :pts/331:S.3 Sun Feb 19 21:43 - 03:51 06:07
testvnc05 out: harman pts/318 :pts/338:S.2 Mon Feb 20 04:04 - 06:19 02:15
testvnc05 out: harman pts/329 :pts/338:S.1 Mon Feb 20 00:55 - 06:19 05:24
testvnc05 out: harman pts/331 192.168.47.44 Sun Feb 19 21:43 - 03:51 06:08
testvnc05 out: harman pts/334 :pts/331:S.1 Sun Feb 19 23:06 - 03:51 04:45
testvnc05 out: harman pts/338 192.168.47.44 Mon Feb 20 00:54 - 06:19 05:25
testvnc05 out: kitagawa pts/302 :24.0 Sun Feb 19 22:20 still logged in
testvnc05 out: kitagawa pts/50 :24.0 Mon Feb 20 18:59 still logged in
testvnc05 out: kvishnu pts/1925 :pts/332:S.4 Mon Feb 20 00:19 - 02:04 01:44
testvnc05 out: kvishnu pts/1925 :pts/332:S.4 Mon Feb 20 02:45 - 03:54 01:08
testvnc05 out: kvishnu pts/1925 :pts/332:S.4 Sun Feb 19 22:27 - 23:33 01:06
testvnc05 out: kvishnu pts/1925 :pts/78:S.4 Sun Feb 19 192:28 - 11:08 00:39
testvnc05 out: kvishnu pts/1927 :pts/332:S.0 Mon Feb 20 00:19 - 02:04 01:44
testvnc05 out: kvishnu pts/1927 :pts/332:S.0 Mon Feb 20 02:45 - 03:54 01:08
testvnc05 out: kvishnu pts/1927 :pts/332:S.0 Sun Feb 19 22:27 - 23:33 01:06
testvnc05 out: kvishnu pts/1192 :pts/332:S.1 Mon Feb 20 00:19 - 02:04 01:44
testvnc05 out: kvishnu pts/1192 :pts/332:S.1 Mon Feb 20 02:45 - 03:54 01:08
testvnc05 out: kvishnu pts/1192 :pts/332:S.1 Sun Feb 19 22:27 - 23:33 01:06
testvnc05 out: kvishnu pts/1192 :pts/78:S.1 Sun Feb 19 192:28 - 11:08 00:39
testvnc05 out: kvishnu pts/113 :pts/332:S.2 Mon Feb 20 00:19 - 02:04 01:44
testvnc05 out: kvishnu pts/113 :pts/332:S.2 Mon Feb 20 02:45 - 03:54 01:08
testvnc05 out: kvishnu pts/113 :pts/332:S.2 Sun Feb 19 22:27 - 23:33 01:06
testvnc05 out: kvishnu pts/113 :pts/78:S.2 Sun Feb 19 192:28 - 11:08 00:39
testvnc05 out: kvishnu pts/129 :pts/332:S.5 Mon Feb 20 00:19 - 02:04 01:44
testvnc05 out: kvishnu pts/129 :pts/332:S.5 Mon Feb 20 02:45 - 03:54 01:08
testvnc05 out: kvishnu pts/129 :pts/332:S.5 Sun Feb 19 22:27 - 23:33 01:06
testvnc05 out: kvishnu pts/129 :pts/78:S.5 Sun Feb 19 192:28 - 11:08 00:39
testvnc05 out: kvishnu pts/138 :pts/332:S.6 Mon Feb 20 00:19 - 02:04 01:44
Solution with awk or shell any one will be okay.
How about a simple:
awk 'NF == 12' File1

how to program in this bash script of background processes

I have three shell scripts say A, B and C. I need to run A in the background and run B in the background till A finishes its execution in the background. Similarly run C in the foreground till A and B finish their execution.
I was doing this for 2 processes earlier in this way.
./A.sh &
while ps -p $! >/dev/null; do
./B.sh
done
I need to run B in background and C in foreground till A finishes its execution in background. How do I modify the above code.
This will run A & B in the background with C in the foreground; B&C will loop until A finishes:
#!/bin/bash
./A.sh &
APID=$!
while ps -p ${APID} >/dev/null; do
./B.sh & ./C.sh
done
Example from my box:
[ 09:39 jon#hozbox.com ~/SO/bash ]$ cat A.sh
#!/bin/bash
echo "A Started at: `date`"
sleep 30
echo "A Finished at: `date`"
[ 09:39 jon#hozbox.com ~/SO/bash ]$ cat B.sh
#!/bin/bash
echo "B Started at: `date`"
sleep 10
echo "B Finished at: `date`"
[ 09:39 jon#hozbox.com ~/SO/bash ]$ cat C.sh
#!/bin/bash
echo "C Started at: `date`"
sleep 5
echo "C Finished at: `date`"
[ 09:38 jon#hozbox.com ~/SO/bash ]$ ./how-to-program-in-this-bash-script-of-background-processes.sh
A Started at: Wed Nov 23 09:38:39 PST 2011
C Started at: Wed Nov 23 09:38:39 PST 2011
B Started at: Wed Nov 23 09:38:39 PST 2011
C Finished at: Wed Nov 23 09:38:44 PST 2011
C Started at: Wed Nov 23 09:38:44 PST 2011
B Started at: Wed Nov 23 09:38:44 PST 2011
B Finished at: Wed Nov 23 09:38:49 PST 2011
C Finished at: Wed Nov 23 09:38:49 PST 2011
C Started at: Wed Nov 23 09:38:49 PST 2011
B Started at: Wed Nov 23 09:38:49 PST 2011
B Finished at: Wed Nov 23 09:38:54 PST 2011
C Finished at: Wed Nov 23 09:38:54 PST 2011
C Started at: Wed Nov 23 09:38:54 PST 2011
B Started at: Wed Nov 23 09:38:54 PST 2011
B Finished at: Wed Nov 23 09:38:59 PST 2011
C Finished at: Wed Nov 23 09:38:59 PST 2011
C Started at: Wed Nov 23 09:38:59 PST 2011
B Started at: Wed Nov 23 09:38:59 PST 2011
B Finished at: Wed Nov 23 09:39:04 PST 2011
C Finished at: Wed Nov 23 09:39:04 PST 2011
C Started at: Wed Nov 23 09:39:04 PST 2011
B Started at: Wed Nov 23 09:39:04 PST 2011
A Finished at: Wed Nov 23 09:39:09 PST 2011
B Finished at: Wed Nov 23 09:39:09 PST 2011
C Finished at: Wed Nov 23 09:39:09 PST 2011
[ 09:39 jon#hozbox.com ~/SO/bash ]$
What about forking A and B at the same time, but put A second so $! gives A's pid:
./B.sh & ./A.sh &
while ps -p $! >/dev/null; do  
./C.sh  
done
Heres an example from my box:
[ 19:08 jon#hozbox.com ~ ]$ date
Tue Nov 22 19:08:19 PST 2011
[ 19:08 jon#hozbox.com ~ ]$ sleep 15 & sleep 20 &
[1] 1126
[2] 1127
[ 19:08 jon#hozbox.com ~ ]$ while ps -p $! > /dev/null; do sleep 1 && date; done
Tue Nov 22 19:08:26 PST 2011
Tue Nov 22 19:08:27 PST 2011
Tue Nov 22 19:08:28 PST 2011
Tue Nov 22 19:08:29 PST 2011
Tue Nov 22 19:08:31 PST 2011
Tue Nov 22 19:08:32 PST 2011
Tue Nov 22 19:08:33 PST 2011
Tue Nov 22 19:08:34 PST 2011
Tue Nov 22 19:08:35 PST 2011
Tue Nov 22 19:08:36 PST 2011
Tue Nov 22 19:08:37 PST 2011
Tue Nov 22 19:08:38 PST 2011
[1]- Done sleep 15
Tue Nov 22 19:08:39 PST 2011
Tue Nov 22 19:08:40 PST 2011
Tue Nov 22 19:08:41 PST 2011
Tue Nov 22 19:08:42 PST 2011
Tue Nov 22 19:08:43 PST 2011
[2]+ Done sleep 20
Tue Nov 22 19:08:44 PST 2011
[ 19:08 jon#hozbox.com ~ ]$
From your picture, it looks like you want B and C to loop while A is running, and then kill both after A completes. Here is the code for that:
# Run A in the background and get its process ID
./A.sh &
PIDA = $!
# Loop B in the background and get its process ID
while ps $PIDA >/dev/null 2>&1; do
./B.sh
done &
PIDB = $!
# Loop C like B, get its PID
while ps $PIDA >/dev/null 2>&1; do
./C.sh
done &
$PIDC = $!
# Wait until A finishes, then kill B and C
wait $PIDA
ps $PIDB >/dev/null 2>&1 && kill $PIDB
ps $PIDC >/dev/null 2>&1 && kill $PIDC

Resources