![]() |
![]() |
![]() |
![]() |
![]() |
Here is my review of Ganymede, for those who missed it: Eclipse Ganymede Review
![]() |
![]() |
![]() |
![]() |
![]() |
awk
instead. Another possible candidate is bc
.
1. Parsing the datesubstr
function as shown below. substr(s,m,n)
returns the n-character substring of s that begins at position m.
today=20080818 echo $today | awk '{ year=substr($1,1,4); month=substr($1,5,2); day=substr($1,7,2); }'If you don't like
awk
, you can also get substrings using the shell's expr
command:
today=20080818 year=`/usr/ucb/expr substr $today 1 4` month=`/usr/ucb/expr substr $today 5 2` day=`/usr/ucb/expr substr $today 7 2`2. Converting to seconds
awk
or bc
for precision.
echo $seconds1 $seconds2 | awk '{print $1 - $2}'or
echo $seconds1 - $seconds2 | bcPutting it all together
#!/usr/bin/bash date1=$1 date2=$2 #give the dates to awk echo $date1 $date2 | awk '{ #parse year1=substr($1,1,4); month1=substr($1,5,2); day1=substr($1,7,2); year2=substr($2,1,4); month2=substr($2,5,2); day2=substr($2,7,2); #get seconds secs1=((year1 - 1970)*365.25+(month1*30.5)+day1)*24*60*60; secs2=((year2 - 1970)*365.25+(month2*30.5)+day2)*24*60*60; #subtract print secs1 - secs2; }'As you can see, all of the computation is in awk! So we could put all of our awk code into a separate file called
subtractDates.awk
, for instance, and run it on the command line like this: echo 20080830 20080818 | awk -f subtractDates.awk
Now that we have the number of seconds between two dates, we can convert that to days, months and years using a similar approach if we have to.
ps
command. For example:
sharfah@starship:~> ps -ef | grep " 1234 " | grep -v grep sharfah 1234 1 0 10:36:06 pts/65 1:20 java -serverHowever, a much neater way to do this is to use the
kill
command to send signal 0 to the process. So kill -0
will not terminate the process and the return status can be used to determine if the process is running. 0 if it is, non-zero otherwise.
sharfah@starship:~> kill -0 1234 sharfah@starship:~> echo $? 0 sharfah@starship:~> kill -0 1234x bash: kill: 1234x: no such pid sharfah@starship:~> echo $? 1For those interested, the
kill -l
command lists signal numbers and names, but 0 is not listed.
sharfah@starship:~> kill -l 1) SIGHUP 2) SIGINT 3) SIGQUIT 4) SIGILL 5) SIGTRAP 6) SIGABRT 7) SIGEMT 8) SIGFPE 9) SIGKILL 10) SIGBUS 11) SIGSEGV 12) SIGSYS 13) SIGPIPE 14) SIGALRM 15) SIGTERM 16) SIGUSR1 17) SIGUSR2 18) SIGCHLD 19) SIGPWR 20) SIGWINCH 21) SIGURG 22) SIGIO 23) SIGSTOP 24) SIGTSTP 25) SIGCONT 26) SIGTTIN 27) SIGTTOU 28) SIGVTALRM 29) SIGPROF 30) SIGXCPU 31) SIGXFSZ 32) SIGWAITING 33) SIGLWP 34) SIGFREEZE 35) SIGTHAW 36) SIGCANCEL 37) SIGLOST
google-reader-subscriptions.xml
file to your computeroutline
elements which represent folders containing RSS feeds.
Here is an excerpt from my newly formatted OPML file, which shows different folders (Fun, Programming, Low Priority) and the feeds within:fuser
is one of the *nix commands that I have started seeing myself use more and more frequently. It is a very powerful command, yet often forgotten. So what is it? fuser
displays the process IDs of the processes that are using the files specified.
Identifying Processesfuser
command to find out which process is writing a log file called log.txt
. fuser
tells you the process ID (24976), which you can then use in a ps
command to find out what the process is. In this case, its java.
sharfah@starship:~> ls -ltr -rw-rw-r-- 1 sharfah sharfah 2836 Aug 6 00:08 log.txt sharfah@starship:~> fuser -u log.txt log.txt: 24976o(sharfah) sharfah@starship:~> ps -ef | grep 24976 sharfah 24976 24963 0 23:49:00 ? 13:39 java -server sharfah 6284 17191 0 00:09:54 pts/1 0:00 grep 24976Used in this way,
fuser
can help tell you which process is responsible for creating large log files on your filesystem!
Killing Processes-k
flag, sends the SIGKILL signal to each process using the file. This is handy if you want to "kill -9" a process without hunting for its PID first. Alternatively, if you want to send another signal type, use the -s
flag. e.g. to send SIGTERM use -s TERM
. The -k
option is equivalent to -s KILL
or -s 9
. Most of my shutdown scripts, simply call fuser -s TERM
on the process's log file.
Because fuser
works with a snapshot of the system image, it
may miss processes that begin using a file while fuser is
running. Also, processes reported as using a file may have
stopped using it while fuser
was running. These factors
should discourage the use of the -k
option.
Thank you for submitting a review of the Eclipse release to the Ganymede Around the World contest. We have an Eclipse shirt for you! Please send me your:I have sent them my details and am looking forward to getting my shirt. I will be posting pictures here as soon as it arrives, so come back soon! Better still, subscribe to my feed! Related post:
1) Name
2) Shirt size (men’s small, medium, large, X-large, 2X-large or women’s small, medium, large)
3) Mailing Address
4) Phone Number (Fedex requires this for deliveries)
The contest closed yesterday, so all blog entries have been passed on to a panel of judges and we hope to have the winners of the Eclipse jackets and conference pass announced in a few weeks. Thank you for participating and best of luck in the contest. Regards,
Lynn Gayowski
Marketing Events Manager
Eclipse Foundation, Inc.
P (613) 224-9461 ext. 234
F (613) 224-5172
lynn.gayowski@eclipse.org
www.eclipse.org