Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Write pid and command name to a txt file while executing a bash script Post 302852971 by Smiling Dragon on Thursday 12th of September 2013 09:57:53 PM
Old 09-12-2013
Current command name is stored in $0
As Spacebar says above, pid is $$

To have it log this to a file, do something like:
Code:
echo "Task: $0 (Pid: $$)" >> logfile.txt

or if you are feeling fancy and want to know when it ran:
Code:
echo "`date` $0 (Pid: $$)" >> logfile.txt

If you need just the last run instead of the log gorwing forever, use a single > instead of >>
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

small script - get sql output & write into txt

Hi, how can I write a small script to run the following statement and output the result into check_result.txt select /*+RULE*/ tapname from typetbl where tapname like 'AA%' and rejectcode=9; Normally, I just type sql and get into SQL> (2 Replies)
Discussion started by: happyv
2 Replies

2. Shell Programming and Scripting

How to read from txt file and write it to xls?

Hello All, I just want help in coding a simple shell script since i am a newbie for UNIX and i started learning unix and shell scripting basics recently. I am having a data like this in .txt file. Product Name : XYZ Price : 678.1 Best Buy Price : 600 Product Name : ABC Price : 465... (3 Replies)
Discussion started by: vasanth_123
3 Replies

3. AIX

Having problem with executing shell script to get the pid details!

Hello Everyone, I am new to shell scripting and also i am very new to AIX machine I have a question. I have shell script which contains the follwing "ps -e |grep $1 echo $2" i run this schell script by doing this ./startSehllscript 3444 passed with two parameters . Accroiding my... (4 Replies)
Discussion started by: swati
4 Replies

4. Shell Programming and Scripting

bash script to sort a txt file

I am writing a script to write to and a sort txt file. After I sort the file I want to add 2 to each line of the file. My script thus far is #!/bin/bash cat > /ramdisk/home/stux/unsortedints.out COUNT=0 FILE =/ramdisk/home/stux/unsortedints.out for i in {1..100} do NUMBER = $ echo $NUMBER... (3 Replies)
Discussion started by: puttyirc
3 Replies

5. Shell Programming and Scripting

write filename as first line in a txt file

Could anyone very kindly help me a simple way to perform the - perhaps - very trivial task of writing the name of a file as first line of that file which is in txt format? And would be possible to do this recursively for some thousands files in the XY directory? And, again, add to the simple... (3 Replies)
Discussion started by: mjomba
3 Replies

6. Shell Programming and Scripting

splitting newfile.txt file and executing each splitted files

split -l $split_count newfile.txt for i in $split_files* do if test -s $workingdir/$split_files* then ./<$i.out> fi done ... (4 Replies)
Discussion started by: sanjay mn
4 Replies

7. Shell Programming and Scripting

how to write bash script that will automatically extract zip file

i'm trying to write a bash script that that will automatically extract zip files after the download. i writed this script #!/bin/bash wget -c https://github.com/RonGokhle/kernel-downloader/zipball/master CURRENDIR=/home/kernel-downloader cd $CURRENDIR rm $CURRENDIR/zipfiles 2>/dev/null ... (2 Replies)
Discussion started by: ron gokhle
2 Replies

8. Shell Programming and Scripting

Call a Perl script within a bash script and store the ouput in a .txt file

I'm attempting to write a bash script that will create a network between virtual machines. It accepts three arguments: an RSpec that describes the network topology, and two list of machines (servers and clients). I have a (working) Perl script that I want to call. This Perl script takes an RSpec... (6 Replies)
Discussion started by: mecaka
6 Replies

9. UNIX for Dummies Questions & Answers

Script to break up file (write new files) in bash

Hello experts, I need help writing individual files from a data matrix, with each new file being written every time there is a blank line: From this cat file.txt col1 col2 col3 6661 7771 8881 6661 7771 8881 6661 7771 8881 col1 col2 col3 3451 2221 1221... (6 Replies)
Discussion started by: torchij
6 Replies

10. Shell Programming and Scripting

Executing sed command inside a bash script

I want to run commands inside a bash script. An example is I want to pass the command in a string as regexp as an argument to the script, then run sed on the bash variable sed.sh regexp sed.sh "-i \"s/<p>//g\"" then call sed "$regexp" $fl (3 Replies)
Discussion started by: Kangol
3 Replies
File::Pid(3pm)						User Contributed Perl Documentation					    File::Pid(3pm)

NAME
File::Pid - Pid File Manipulation SYNOPSIS
use File::Pid; my $pidfile = File::Pid->new({ file => '/some/file.pid', }); $pidfile->write; if ( my $num = $pidfile->running ) { die "Already running: $num "; } $pidfile->remove; DESCRIPTION
This software manages a pid file for you. It will create a pid file, query the process within to discover if it's still running, and remove the pid file. new my $pidfile = File::Pid->new; my $thisfile = File::Pid->new({ file => '/var/run/daemon.pid', }); my $thisfileandpid = File::Pid->new({ file => '/var/run/daemon.pid', pid => '145', }); This constructor takes two optional paramters. "file" - The name of the pid file to work on. If not specified, a pid file located in "File::Spec->tmpdir()" will be created that matches "(File::Basename::basename($0))[0] . '.pid'". So, for example, if $0 is ~/bin/sig.pl, the pid file will be /tmp/sig.pl.pid. "pid" - The pid to write to a new pidfile. If not specified, $$ is used when the pid file doesn't exist. When the pid file does exist, the pid inside it is used. file my $pidfile = $pidfile->file; Accessor/mutator for the filename used as the pid file. pid my $pid = $pidfile->pid; Accessor/mutator for the pid being saved to the pid file. write my $pid = $pidfile->write; Writes the pid file to disk, inserting the pid inside the file. On success, the pid written is returned. On failure, "undef" is returned. running my $pid = $pidfile->running; die "Service already running: $pid " if $pid; Checks to see if the pricess identified in the pid file is still running. If the process is still running, the pid is returned. Otherwise "undef" is returned. remove $pidfile->remove or warn "Couldn't unlink pid file "; Removes the pid file from disk. Returns true on success, false on failure. program_name This is a utility method that allows you to determine what "File::Pid" thinks the program name is. Internally this is used when no pid file is specified. SEE ALSO
perl. AUTHOR
Casey West, <casey@geeknest.com>. COPYRIGHT
Copyright (c) 2005 Casey West. All rights reserved. This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. perl v5.8.8 2008-04-05 File::Pid(3pm)
All times are GMT -4. The time now is 08:08 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy