scripting: output afkappen na spatie

Pagina: 1
Acties:

  • flapdrol85
  • Registratie: Juni 2004
  • Niet online
Ik ben bezig met een kort script dat mijn w850i synced met kontact. Daarvoor maak ik onder andere gebruik van MyPhoneExplorer onder Wine. Deze synced mijn telefoon met een iCal bestand. Dit bestand kopieer ik dan dmv een script later naar de map van Kontact. Om kontact dit iCal echter te laten inlezen moet ik het programma afsluiten en opnieuw opstarten. Daarvoor moet ik eerst de PID achterhalen. Dat is geen probleem, door

top -u rob -b -n 1 | grep kontact

te doen kom ik daar wel achter. Het probleem is echter dat ik uit deze output alleen de eerste kolom nodig ben (dat is namelijk de pid). De rest van de output is nutteloos. Ik heb al gegoogled de manpages van SED en AWK gelezen en een aantal scripting how to's gelezen. Ik kom er echter niet uit. Ook

top -u rob -b -n 1 | grep kontact | cut -d ',' -f 1

levert niet het gewenste resultaat op. Wie heeft er een idee?

  • blaataaps
  • Registratie: Juli 2001
  • Niet online
Ten eerste, als je al grep wil gebruiken, waarom niet op de output van ps ipv top, en ken je pgrep? :)

  • Jaap-Jan
  • Registratie: Februari 2001
  • Laatst online: 03:02
Als je een spatie als 'delimiter' wilt, waarom stel je dan een komma in? ;)

@blaataaps: ik kende pgrep ook niet, wel handig. :)

[ Voor 26% gewijzigd door Jaap-Jan op 25-03-2008 11:04 ]

| Last.fm | "Mr Bent liked counting. You could trust numbers, except perhaps for pi, but he was working on that in his spare time and it was bound to give in sooner or later." -Terry Pratchett


  • flapdrol85
  • Registratie: Juni 2004
  • Niet online
@Blaat-aaps: Perfect, ik kende pgrep idd nog niet. Ideaal. Thanks..

@jaap-jan, dat was een foutje. Ik had wel de spatie gebruikt.

  • Whieee
  • Registratie: Augustus 2001
  • Laatst online: 29-01 16:38

Whieee

Moderator Apple Talk

⌘ + ⌥ + ⎋

ps x | grep kontact | awk '!/grep/ {print $1}'

Launching containers into space


  • u_nix_we_all
  • Registratie: Augustus 2002
  • Niet online
code:
1
killall kontact

You don't need a parachute to go skydiving. You need a parachute to go skydiving twice.


  • flapdrol85
  • Registratie: Juni 2004
  • Niet online
Inmiddel heb ik het al voor elkaar door middel van pgrep.

@u_nix_we_all : is dat niet een vuile manier om het programma hard te killen. Ik wil dat het programma nog netjes afsluit

  • smokalot
  • Registratie: Juni 2001
  • Laatst online: 15-01 22:00

smokalot

titel onder

flapdrol85 schreef op woensdag 26 maart 2008 @ 14:29:
Inmiddel heb ik het al voor elkaar door middel van pgrep.

@u_nix_we_all : is dat niet een vuile manier om het programma hard te killen. Ik wil dat het programma nog netjes afsluit
killall stuurt standaard het signaal TERM (15) naar het programma, wat het programma de kans geeft af te sluiten. Als je het signaal KILL (9) geeft mag het programma dat niet blocken, en moet het direct afsluiten. Zie man killall.

It sounds like it could be either bad hardware or software


  • Seth4Chaos
  • Registratie: Maart 2001
  • Niet online

Seth4Chaos

that's me...

kill, killall en pkill geven allemaal (standaard) een TERM (15) signal. Al deze programma's kan je een -9 o.i.d. meegeven voor een KILL (9) signal.

Ik vermoed dat jij na je 'pgrep kontact' een kill stuurt naar dit prog (wat overigens sneller kan met "pkill kontact"). Al deze opties sturen een TERM naar kontact waarbij die netjes aflsuit, roep je een van deze commando's aan met een '-9' erbij dan wordt die niet netjes afgesloten.

Mistakes are proof that you are trying...


  • u_nix_we_all
  • Registratie: Augustus 2002
  • Niet online
smokalot schreef op woensdag 26 maart 2008 @ 14:40:
[...]

killall stuurt standaard het signaal TERM (15) naar het programma, wat het programma de kans geeft af te sluiten. Als je het signaal KILL (9) geeft mag het programma dat niet blocken, en moet het direct afsluiten. Zie man killall.
Man killall:
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
 killall(1M)                                                     killall(1M)

 NAME
      killall - kill all active processes

 SYNOPSIS
      /usr/sbin/killall [signal]

 DESCRIPTION
      killall is a procedure used by /usr/sbin/shutdown to kill all active
      processes not directly related to the shutdown procedure.

      killall is chiefly used to terminate all processes with open files so
      that the mounted file systems are no longer busy and can be unmounted.
      killall sends the specified signal to all user processes in the
      system, with the following exceptions:

           the init process;

           all processes (including background processes) associated with
           the terminal from which killall was invoked;

           any ps -ef process, if owned by root;

           any sed -e process, if owned by root;

           any shutdown process;

           any killall process;

           any /sbin/rc process.

      killall obtains its process information from ps, and therefore may not
      be able to perfectly identify which processes to signal (see ps(1)).

      If no signal is specified, a default of 9 (kill) is used.

      killall is invoked automatically by shutdown The use of shutdown is
      recommended over using killall by itself (see shutdown(1M)).

 FILES
      /usr/sbin/shutdown

 SEE ALSO
      fuser(1M), kill(1), ps(1), shutdown(1M), signal(5).

 STANDARDS CONFORMANCE
      killall: SVID2, SVID3

 Hewlett-Packard Company            - 1 -  HP-UX Release 11.00: October 1997


Beetje flauw en offtopic misschien, maar eigenlijk heb ik zelf slechte ervaringen met killall. Niet, ik herhaal: niet gebruiken op HP-UX om een procesje te killen ;)

You don't need a parachute to go skydiving. You need a parachute to go skydiving twice.


  • luteijn
  • Registratie: Maart 2008
  • Laatst online: 16-12-2022
"Nooit zomaar killall gebruiken", was ook het eerste dat ik dacht toen ik die killall-suggestie zag staan. Werkt prima op linux, maar op HP/UX en ook op SUN killt het alle processen. Ook al eens ingetrapt, helaas.

code:
1
2
3
4
5
6
7
8
Maintenance Commands                                  killall(1M)


NAME
     killall - kill all active processes
...snip...

SunOS 5.8            Last change: 14 Sep 1992                   1

  • Rainmaker
  • Registratie: Augustus 2000
  • Laatst online: 14-07-2024

Rainmaker

RHCDS

Even tussen haakjes, in man killall staan de signals niet uitgelegd (bij mij niet in ieder geval).

Enige plaats waar ik ze in man heb kunnen vinden is in man 7 signal.

code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
       First the signals described in the original POSIX.1 standard.

       Signal     Value     Action   Comment
       -------------------------------------------------------------------------
       SIGHUP        1       Term    Hangup detected on controlling terminal
                                     or death of controlling process
       SIGINT        2       Term    Interrupt from keyboard
       SIGQUIT       3       Core    Quit from keyboard
       SIGILL        4       Core    Illegal Instruction
       SIGABRT       6       Core    Abort signal from abort(3)
       SIGFPE        8       Core    Floating point exception
       SIGKILL       9       Term    Kill signal
       SIGSEGV      11       Core    Invalid memory reference
       SIGPIPE      13       Term    Broken pipe: write to pipe with no readers
       SIGALRM      14       Term    Timer signal from alarm(2)
       SIGTERM      15       Term    Termination signal
       SIGUSR1   30,10,16    Term    User-defined signal 1
       SIGUSR2   31,12,17    Term    User-defined signal 2
       SIGCHLD   20,17,18    Ign     Child stopped or terminated
       SIGCONT   19,18,25            Continue if stopped
       SIGSTOP   17,19,23    Stop    Stop process
       SIGTSTP   18,20,24    Stop    Stop typed at tty
       SIGTTIN   21,21,26    Stop    tty input for background process
       SIGTTOU   22,22,27    Stop    tty output for background process

       The signals SIGKILL and SIGSTOP cannot be caught, blocked, or ignored.

       Next the signals not in the POSIX.1 standard but described in SUSv2 and SUSv3 / POSIX 1003.1-2001.

       Signal       Value     Action   Comment
       -------------------------------------------------------------------------
       SIGBUS      10,7,10     Core    Bus error (bad memory access)
       SIGPOLL                 Term    Pollable event (Sys V). Synonym of SIGIO
       SIGPROF     27,27,29    Term    Profiling timer expired
       SIGSYS      12,-,12     Core    Bad argument to routine (SVID)
       SIGTRAP        5        Core    Trace/breakpoint trap
       SIGURG      16,23,21    Ign     Urgent condition on socket (4.2 BSD)
       SIGVTALRM   26,26,28    Term    Virtual alarm clock (4.2 BSD)
       SIGXCPU     24,24,30    Core    CPU time limit exceeded (4.2 BSD)
       SIGXFSZ     25,25,31    Core    File size limit exceeded (4.2 BSD)

       Up  to  and  including  Linux  2.2, the default behaviour for SIGSYS, SIGXCPU, SIGXFSZ, and (on architectures other than SPARC and
       MIPS) SIGBUS was to terminate the process (without a core dump).  (On some other Unices the default action for SIGXCPU and SIGXFSZ
       is  to  terminate  the  process without a core dump.)  Linux 2.4 conforms to the POSIX 1003.1-2001 requirements for these signals,
       terminating the process with a core dump.

       Next various other signals.

       Signal       Value     Action   Comment
       --------------------------------------------------------------------
       SIGIOT         6        Core    IOT trap. A synonym for SIGABRT
       SIGEMT       7,-,7      Term
       SIGSTKFLT    -,16,-     Term    Stack fault on coprocessor (unused)
       SIGIO       23,29,22    Term    I/O now possible (4.2 BSD)
       SIGCLD       -,-,18     Ign     A synonym for SIGCHLD
       SIGPWR      29,30,19    Term    Power failure (System V)
       SIGINFO      29,-,-             A synonym for SIGPWR
       SIGLOST      -,-,-      Term    File lock lost
       SIGWINCH    28,28,20    Ign     Window resize signal (4.3 BSD, Sun)
       SIGUNUSED    -,31,-     Term    Unused signal (will be SIGSYS)

       (Signal 29 is SIGINFO / SIGPWR on an alpha but SIGLOST on a sparc.)


offtopic:
En ik heb ook eens killall op Tru64 gebruikt :X Is volgens mij echt een typische beginnersfout :)

We are pentium of borg. Division is futile. You will be approximated.

Pagina: 1