Sponsored Content
Top Forums Shell Programming and Scripting test script to identify SHELL Post 302347805 by vgersh99 on Wednesday 26th of August 2009 12:23:57 PM
Old 08-26-2009
Code:
#!/bin/sh

pid="$$"
echo "myShell->[`ps -o 'pid,comm' -p "${pid}" | nawk 'FNR==2{print $2}'`]"

YMMV - not generic

Last edited by vgersh99; 08-26-2009 at 01:30 PM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

need help with test condition in shell script

I'm new to scripting and I need help with a bourn shell script. What i'm trying to do is a test condition where "if the time is within 2 hours, it's true" and so on. The time is in the following format DATE=`/bin/date +"%Y%m%d%H%S"` for example, 20060907152000. So, what the script first... (9 Replies)
Discussion started by: pieman8080
9 Replies

2. Shell Programming and Scripting

Test for shell interpreter at beginning of script

What would be the best way or method to determine or test for the shell interpreter at the beginning of a script in the event one shell is not available? If I use the following: #!/bin/bash and /bin/bash is not available, then use I'd like to use /bin/ksh if it is available. #!/bin/ksh (8 Replies)
Discussion started by: nck
8 Replies

3. Shell Programming and Scripting

-a test in shell script

I need clarification in -a test. If say, in test -a left expression is not present but the right expression is present, do the shell will consider the left expression true and evaluate the right expression? For example: if ] then rm -f ${file} fi Is this test condition... (7 Replies)
Discussion started by: jatanig
7 Replies

4. Shell Programming and Scripting

Shell script to identify the number of files and to append data

Hi I am having a question where I have to 1) Identify the number of files in a directory with a specific format and if the count is >1 we need to concatenate those two files into one file and remember that in the second file the header should not be copied. it should be form first file.... (4 Replies)
Discussion started by: pradkumar
4 Replies

5. Shell Programming and Scripting

Help with connectivity test using shell script

I want to test connectivity between different servers with my server using information as IP and port only. I have Name,IP List and port in one file. Please help how i can test connectivity is successful or not? File format will be: Name1,127.0.0.1,80 Name2,127.0.0.2,8080 Output could be ... (1 Reply)
Discussion started by: poweroflinux
1 Replies

6. UNIX for Dummies Questions & Answers

Test: argument expected error in shell script

Hi, I am trying to write a small script that validates if there exist files that start with a pattern in a given directory. Below is the piece of my script: #!/usr/bin/ksh BTFDIR=/opt/ships/temp if then echo 'found' else echo 'not found' fi When I run this... (2 Replies)
Discussion started by: snvniranjanrao
2 Replies

7. Shell Programming and Scripting

Identify variables used in the shell script

Hi, Is there any simple way to get/identify the variables that are used in a file and print those variable names. If I have something like this in a file, /$var/temp_dir/${var2}${var3}.log I want to display the variables 'var', 'var2' and 'var3' from that file. I tried something like... (6 Replies)
Discussion started by: pvamsikr
6 Replies

8. Shell Programming and Scripting

Test shell script (PROBLEM)

Dears , kindly I wanna do test for one KSH script to know how is it working , the problem that I'm facing is whenever put "sh -x ./my_script.sh" the output seems very long & although I tried to to redirect it to files as it shown , but it failed :eek: :- sh -x ./my_script.sh >... (2 Replies)
Discussion started by: arm
2 Replies

9. UNIX for Dummies Questions & Answers

Shell Script to test telnet connection using port

Hello, I need to test telnet connections using port number for few hosts. Could you please help me? Thanks !! (1 Reply)
Discussion started by: skhichi
1 Replies

10. Shell Programming and Scripting

Help with Shell Script to identify lines in file1 and write them to file2

Hi, I am running my pipeline and capturing all stout from multiple programs to a .txt file. I want to go into that .txt file and search for specific lines, and finally print those lines in a second .txt file. I can do this using grep, awk, or sed for each line, but have not been able to get... (2 Replies)
Discussion started by: hmortens
2 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 01:42 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy