Sponsored Content
Full Discussion: Hit count on a shell script
Top Forums Shell Programming and Scripting Hit count on a shell script Post 302477176 by Corona688 on Friday 3rd of December 2010 12:57:26 PM
Old 12-03-2010
What is your system? What is your shell?

You have to stop people from using your count file at the same time. Not knowing your system I use a fifo as a sem, you have to succeed in creating it before you can read or write the count file. Not ideal, and someone could DOS it(leave junk in /tmp/script-fifo so everyone waits forever). A database of some sort would be better but I have no idea what you have.
Code:
# Use a fifo as an ad-hoc semaphore.
# Only one script can create it at a time, the rest
# will wait.
while ! mkfifo /tmp/script-fifo 2> /dev/null
do
        sleep 1
done

COUNT=0
[ -f /path/to/countfile ] && read COUNT < /path/to/countfile
((COUNT++))
echo $COUNT > /path/to/countfile
rm -f /tmp/script-fifo

echo "script has been called $COUNT times"

...

/path/to/countfile must be a file which is writable by anyone running the script.
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Perl/shell script count the lines

Hi Guys, I want to write a perl/shell script do parse the following file input file content NPA-NXX SC 2084549 45 2084552 45 2084563 2007 2084572 45 2084580 45 3278411 45 3278430 45 3278493 530 3278507 530... (3 Replies)
Discussion started by: pistachio
3 Replies

2. Shell Programming and Scripting

Shell Script to hit a url

Hi all, I have a php file that grabs xml, parses it and updates my db accordingly. I want to automate the execution of this process, rather than having to hit the url manually. I have been looking into using cron to execute a script to do this, however i'm not exactly sure what command i would... (1 Reply)
Discussion started by: restivz77
1 Replies

3. Shell Programming and Scripting

shell script to get the arrival count of file

Hello All, I have come across a small problem. It would be great if any of you could help me in resolving the issue. one file named dummy.txt will be ftped to Unix machine twice daily. If i receive it second time in a day i need to do some processing with the file. How to find the... (2 Replies)
Discussion started by: RSC1985
2 Replies

4. Shell Programming and Scripting

count and compare no of records in bash shell script.

consider this as a csv file. H,0002,0002,20100218,17.25,P,barani D,1,2,3,4,5,6,7,8,9,10,11 D,1,2,3,4,5,6,7,8,9,10,11 D,1,2,3,4,5,6,7,8,9,10,11 D,1,2,3,4,5,6,7,8,9,10,11 D,1,2,3,4,5,6,7,8,9,10,11 T,5 N i want to read the csv file and count the number of rows that start with D and... (11 Replies)
Discussion started by: barani75
11 Replies

5. Shell Programming and Scripting

count multiple objects in shell script

Hi all: Trying to count the number of oracle instances on HPUX 11.23 - using ksh. I have multiple instances running and I would like to have a count for how many processes for each instance. Example, run the 'ps -efu oracle' command and for each instance increment a counter. So I am looking for... (4 Replies)
Discussion started by: raggmopp
4 Replies

6. Shell Programming and Scripting

Shell script to count unique rows in a CSV

HI All, I have a CSV file of 30 columns separated by ,. I want to get a count of all unique rows written to a flat file. The CSV file is around 5000 rows The first column is a time stamp and I need to exclude while counting unique Thanks, Ravi (4 Replies)
Discussion started by: Nani369
4 Replies

7. Shell Programming and Scripting

Print record count of a file using shell script

HI, I need to print the record count of a file using shell script. If the record count of a file excluding header and trailer record if greater than zero then print 'Record count of a file is xxxx records'. If the record count is zero print 'zero records' Thanks Mahendra (1 Reply)
Discussion started by: mmeda
1 Replies

8. Shell Programming and Scripting

Validate file count in korn shell script

Hi, I have files in the directory like below which I need to validate if all the required files are present. A_B_001 of 002_time1.txt A_B_002 of 002_time1.txt A_B_001 of 001_time2.txt Scenarios- a)If file with 001 of 002_time1 or 002 of 002_time1 is missing in the folder,script should... (6 Replies)
Discussion started by: aneeta13
6 Replies

9. Shell Programming and Scripting

File Count Based on FileDate using Shell Script

I have file listed in my directory in following format -rwxrwxr-x+ 1 test test 4.9M Oct 3 16:06 test20141002150108.txt -rwxrwxr-x+ 1 test test 4.9M Oct 4 16:06 test20141003150108.txt -rwxrwxr-x+ 1 test test 4.9M Oct 5 16:06 test20141005150108.txt -rwxrwxr-x+ 1 test ... (2 Replies)
Discussion started by: krish2014
2 Replies

10. Shell Programming and Scripting

Script Shell: Count The sum of numbers in a file

Hi all; Here is my file: V1.3=4 V1.4=5 V1.1=3 V1.2=6 V1.3=6 Please, can you help me to write a script shell that counts the sum of values in my file (4+5+3+6+6) ? Thank you so much for help. Kind regards. (3 Replies)
Discussion started by: chercheur111
3 Replies
MKFIFO(2)						      BSD System Calls Manual							 MKFIFO(2)

NAME
mkfifo -- make a fifo file SYNOPSIS
#include <sys/types.h> #include <sys/stat.h> int mkfifo(const char *path, mode_t mode); DESCRIPTION
Mkfifo() creates a new fifo file with name path. The access permissions are specified by mode and restricted by the umask(2) of the calling process. The fifo's owner ID is set to the process's effective user ID. The fifo's group ID is set to that of the parent directory in which it is created. RETURN VALUES
A 0 return value indicates success. A -1 return value indicates an error, and an error code is stored in errno. ERRORS
Mkfifo() will fail and no fifo will be created if: [EOPNOTSUPP] The kernel has not been configured to support fifo's. [ENOTDIR] A component of the path prefix is not a directory. [ENAMETOOLONG] A component of a pathname exceeded {NAME_MAX} characters, or an entire path name exceeded {PATH_MAX} characters. [ENOENT] A component of the path prefix does not exist. [EACCES] Search permission is denied for a component of the path prefix. [ELOOP] Too many symbolic links were encountered in translating the pathname. [EROFS] The named file resides on a read-only file system. [EEXIST] The named file exists. [ENOSPC] The directory in which the entry for the new fifo is being placed cannot be extended because there is no space left on the file system containing the directory. [ENOSPC] There are no free inodes on the file system on which the fifo is being created. [EDQUOT] The directory in which the entry for the new fifo is being placed cannot be extended because the user's quota of disk blocks on the file system containing the directory has been exhausted. [EDQUOT] The user's quota of inodes on the file system on which the fifo is being created has been exhausted. [EIO] An I/O error occurred while making the directory entry or allocating the inode. [EIO] An I/O error occurred while reading from or writing to the file system. [EFAULT] Path points outside the process's allocated address space. SEE ALSO
chmod(2), stat(2), umask(2) STANDARDS
The mkfifo function call conforms to IEEE Std 1003.1-1988 (``POSIX.1''). BSD
June 4, 1993 BSD
All times are GMT -4. The time now is 02:56 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy