Home Man
Search
Today's Posts
Register

BSD, Linux, and UNIX shell scripting — Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

How to check same process running 10 times?

Tags
shell scripts

Login to Reply

 
Thread Tools Search this Thread
# 15  
Old 11-10-2017
Thanks a lot for ur quick respond Am runing below script passing 1 because no duplicate job runing now it giving correct output-AIX operating system

my question::Will it work if runing more then 10 time or will it compaire please confirm
Code:
awk '++s[$2]==10'

Code:
jobs=$(ps -u pintu -o pid= -o args=| awk '++s[$2]==1')
if [[ -n "$jobs" ]]
then
  printf "jobs runing longtime:\n%s\n" "$jobs"
  exit 1
fi

see the below output also
Code:
jobs runing longtime:
 2362 /usr/bin/gnome-keyring-daemon --daemonize --login
 2371 gnome-session
 2380 dbus-launch --sh-syntax --exit-with-session
 2381 /bin/dbus-daemon --fork --print-pid 5 --print-address 7 --session
 2399 /usr/libexec/gconfd-2
 2406 /usr/libexec/gnome-settings-daemon
 2408 seahorse-daemon
 2415 /usr/libexec/gvfsd
 2423 metacity
 2434 /usr/bin/pulseaudio --start --log-target=syslog
 2435 gnome-panel
 2440 /usr/libexec/pulse/gconf-helper
 2441 nautilus
 2443 /usr/libexec/bonobo-activation-server --ac-activate --ior-output-fd=18
 2453 /usr/libexec/gvfs-gdu-volume-monitor
 2454 /usr/libexec/wnck-applet --oaf-activate-iid=OAFIID:GNOME_Wncklet_Factory --oaf-ior-fd=18
 2455 /usr/libexec/trashapplet --oaf-activate-iid=OAFIID:GNOME_Panel_TrashApplet_Factory --oaf-ior-fd=24
 2459 /usr/lib/vmware-tools/sbin32/vmtoolsd -n vmusr --blockFd 3
 2467 gpk-update-icon
 2470 gnome-power-manager
 2474 gnome-volume-control-applet
 2476 bluetooth-applet
 2480 /usr/sbin/restorecond -u
 2482 /usr/libexec/polkit-gnome-authentication-agent-1
 2485 python /usr/share/system-config-printer/applet.py
 2486 /usr/libexec/gdu-notification-daemon
 2489 nm-applet --sm-disable
 2494 /usr/libexec/gvfs-afc-volume-monitor
 2498 /usr/libexec/gvfsd-trash --spawner :1.7 /org/gtk/gvfs/exec_spaw/0
 2502 /usr/libexec/gvfs-gphoto2-volume-monitor
 2509 gnome-screensaver
 2518 /usr/bin/gnote --panel-applet --oaf-activate-iid=OAFIID:GnoteApplet_Factory --oaf-ior-fd=23
 2519 /usr/libexec/clock-applet --oaf-activate-iid=OAFIID:GNOME_ClockApplet_Factory --oaf-ior-fd=29
 2520 /usr/libexec/notification-area-applet --oaf-activate-iid=OAFIID:GNOME_NotificationAreaApplet_Factory --oaf-ior-fd=39
 2521 /usr/libexec/gdm-user-switch-applet --oaf-activate-iid=OAFIID:GNOME_FastUserSwitchApplet_Factory --oaf-ior-fd=35
 2562 /usr/libexec/gvfsd-burn --spawner :1.7 /org/gtk/gvfs/exec_spaw/1
 2569 /usr/libexec/gvfsd-metadata
 2575 /usr/bin/gnome-terminal -x /bin/sh -c cd '/home/pintu/Desktop' && exec $SHELL -l
 2576 gnome-pty-helper
 2577 /bin/bash -l
 2843 sh t2.sh
 2845 ps -u pintu -o pid= -o args=
 2846 awk ++s[$2]==1

# 16  
Old 11-15-2017
The
Code:
awk '++s[$2]==10'

lists the 10th occurrence of column#2, and if there are more than 10 it will not wipe a previously printed one
You can search for certain strings through the whole line like this
Code:
awk '(index($0, "a.ksh") || index($0, "d.ksh") && ++s[$2]==10'

and this should work with the args.
Regarding "jobs running longtime", perhaps etime (elapsed time) is more interesting:
Code:
ps -e -o pid= -o etime= -o args=

And now your task is to have the postprocessor (awk) compute a comparible number from the etime column.
Login to Reply

« Previous Thread | Next Thread »
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
ksh script to check if certain process is running seekryts15 Shell Programming and Scripting 6 12-29-2014 12:41 PM
How a process can check if a particular process is running on different machine? saurabhnsit2001 UNIX for Dummies Questions & Answers 2 06-02-2012 11:14 PM
need to check if the process is running shifahim Shell Programming and Scripting 8 08-18-2011 10:17 PM
How do I check if a process is running in C cprogdude Programming 1 10-12-2010 05:01 AM
How to check if process is running? ladyAnne UNIX and Linux Applications 5 05-01-2010 01:20 AM
Check if Process is running Raynon Shell Programming and Scripting 3 01-08-2010 02:03 AM
Check process running Status with PID 1nsyz1on Shell Programming and Scripting 9 11-18-2009 04:03 AM
how to check how long the process has been running. ukatru UNIX for Advanced & Expert Users 2 08-17-2008 08:22 PM
Check whether ftpd process is running or not? The.White.Rider Solaris 8 06-17-2008 07:51 AM
check process running rose1207 Shell Programming and Scripting 4 12-28-2007 12:23 AM


All times are GMT -4. The time now is 02:54 AM.

Unix & Linux Forums Content Copyright©1993-2018. All Rights Reserved.
UNIX.COM Login
Username:
Password:  
Show Password