Get process id

I bet there’s an easier way to do this.

I need to get the pid of the command that started a process-typically ‘sudo shutdown’

I started the shutdown with:

sudo shutdown -h +120

The command to get just the pid is:

ps -ef | grep 'sudo shutdown -h' | grep -v 'grep' | awk '{print $2}'

or

ps ax | grep 'sudo shutdown -h' | grep -v 'grep' | awk '{print $1}'

-v excludes our current command from results.

The awk command prints the labelled coloumn of output only.


You are reading this post on Joel G Mathew’s tech blog. Joel's personal blog is the Eyrie, hosted here.

Find total number of files different in a patch

droidzone ~/android $ grep -n '^\-\-\-' kerneldiff.patch                                                                                                              
2:--- oldkernel/.config 1969-12-31 17:00:00.000000000 -0700                                                                                                           
3341:--- oldkernel/.version     1969-12-31 17:00:00.000000000 -0700                                                                                                   
3346:--- oldkernel/Makefile     2012-09-04 17:06:16.000000000 -0700                                                                                                   
3375:--- oldkernel/Makefile~    1969-12-31 17:00:00.000000000 -0700                                                                                                   
4958:--- oldkernel/Module.symvers       1969-12-31 17:00:00.000000000 -0700                                                                                           
10537:--- oldkernel/include/config/auto.conf    1969-12-31 17:00:00.000000000 -0700                                                                                   
11651:--- oldkernel/include/config/auto.conf.cmd        1969-12-31 17:00:00.000000000 -0700                                                                           
12408:--- oldkernel/include/config/kernel.release       1969-12-31 17:00:00.000000000 -0700                                                                           
12413:--- oldkernel/include/config/tristate.conf        1969-12-31 17:00:00.000000000 -0700                                                                           
12810:--- oldkernel/include/generated/asm-offsets.h     1969-12-31 17:00:00.000000000 -0700                                                                           
12885:--- oldkernel/include/generated/autoconf.h        1969-12-31 17:00:00.000000000 -0700                                                                           
13999:--- oldkernel/include/generated/bounds.h  1969-12-31 17:00:00.000000000 -0700                                                                                   
14017:--- oldkernel/include/generated/compile.h 1969-12-31 17:00:00.000000000 -0700                                                                                   
14028:--- oldkernel/include/generated/mach-types.h      1969-12-31 17:00:00.000000000 -0700                                                                           
28382:--- oldkernel/include/generated/utsrelease.h      1969-12-31 17:00:00.000000000 -0700                                                                           
28387:--- oldkernel/include/linux/version.h     1969-12-31 17:00:00.000000000 -0700                                                                                   
28396:--- oldkernel/scripts/genksyms/keywords.c 1969-12-31 17:00:00.000000000 -0700                                                                                   
28620:--- oldkernel/scripts/genksyms/lex.c      1969-12-31 17:00:00.000000000 -0700                                                                                   
31206:--- oldkernel/scripts/genksyms/parse.c    1969-12-31 17:00:00.000000000 -0700                                                                                   
33730:--- oldkernel/scripts/genksyms/parse.h    1969-12-31 17:00:00.000000000 -0700                                                                                   
33833:--- oldkernel/scripts/kconfig/lex.zconf.c 1969-12-31 17:00:00.000000000 -0700                                                                                   
36273:--- oldkernel/scripts/kconfig/zconf.hash.c        1969-12-31 17:00:00.000000000 -0700                                                                           
36522:--- oldkernel/scripts/kconfig/zconf.tab.c 1969-12-31 17:00:00.000000000 -0700                                                                                   
39031:--- oldkernel/scripts/mod/elfconfig.h     1969-12-31 17:00:00.000000000 -0700

 


You are reading this post on Joel G Mathew’s tech blog. Joel's personal blog is the Eyrie, hosted here.

A simple example of SED

The basic command for replacing occurences of a particular string in a file to another string and output to a new file:

Let’s call our source file file1

sed 's/'old string'/'new string'/' file1

Example
sed 's,'CONFIG_TUN=m','#CONFIG_TUN=m','lconfig

This will output the replaced text to screen. If you want to make changes in the file, you need to pipe it to a new file and finally move the file back to original name.

sed 's/'old string'/'new string'/' file1 > file2 ; mv file2 file1[/code]
And to test if it was successful:
grep -i 'new string' destinationfile

You are reading this post on Joel G Mathew’s tech blog. Joel's personal blog is the Eyrie, hosted here.