Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

brauche Shellscript Prozedur....

Empfohlene Antworten

Veröffentlicht

Hoi,

ich möchte gerne einem Shellscript eine Prozedur hinzufügen, die die Verhinderung einer gleichzeitigen Ausführung abschaltet.

Auf deutsch:

Ich will per Variable einstellen können, ob das Programm (Shellscript) nur einmal laufen darf oder auch öfters.

Ich dachte mir dass ich das Problem mit dem "spezialvariablen $$", die die PID des aktuellen Prozesses wiedergeben, lösen kann. Jedoch komm ich nicht weiter :(

Für Hilfe wäre ich dankbar!!

Hier mal ein Beispielcode, wie ich mir das ungefähr vorstelle: (nur mal so hingerotzt)

# concurrent execution

exe=0 # ""|0: no concurrent execution

if test -z "$exe"; then exe=0; fi #$progname could be only 1 time executed # 1: concurrent execution on

if test "$exe" -gt 0; then concurentexe;

fi

if test "$exe" -gt 0; then tmpext=$$; else tmpext=tmp; fi

tmpfile=${TMP:-/tmp}/${progname%%.*}.$tmpext

concurrentexe ()

{

if test "$tmpfile" = "$tmpfile"; then

echo "concurrent execution: Sorry, $progname is processing, please wait..."

fi

}

Hi,

$$ ist ja die ID des gerade laufenden Prozess.

Uberpruef einfach ob die ID in der Prozessliste enthalten ist

z.B. ps -ef | grep "prozessname | grep -v grep | awk '{print $2}'

Mit diesem Kommando suchst du den Prozess und gibst , falls er vorhanden ist die ID aus.

Dann noch schnell $$ und die ID vergleichen und schon hast du die Abfrage...

ausserdem wuerd ich in das TMPFILE noch $$ miteinbauen, damit es eindeutig ist.

  • Autor

also ich hab hier erstmal eine Prozedur erstellt, die eine gleichzeitige Ausführung verhindert... (um diese Prozedur zu verhindern benötige ich eine andere....ich bleib dran)

code:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

LockExec ()

{

test -z "$conffile" -o ! -f "$conffile" && return 0

pidfile="$conffile.$$"

echo $$ >$pidfile

ln $pidfile $conffile.lock 2>/dev/null && return 0

CritError "already running as pid '$(<$conffile.lock)'."

}

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

so long,

Archiv

Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.