11-28-2017
Quote:
Originally Posted by
greenworld123
the process prints some garbage and then with proper text. it is not the process writing garbage i think.
I think you have already gotten very good advice about how to solve it but it might be helping you to understand what is going on:
When a process "opens" a file it calls some OS function (namely
fopen()) and part of this "opening" is that the OS sets up an environment through which the process can access the file. Part of this is to find out how big (=how many bytes) a file is. The process also gets a "place" where it "stands" right now. This "place" can be moved forward, backwards, etc., but only within the limits of the length of the file.
Say, a program opens a file and is told that the file is 10 bytes long. Right now it "stands" on byte 1 and it can read it, which would move the place it stands forward to byte 2, etc.. It can also do things like "go forward 3 bytes and then read (or write) 2 bytes from there". It can also add to the file, which would increase the size so that now it can position its place to byte 11. But if it tries to do something impossible (like "go to byte number <behind the current length>" it would receive an error because the OS "knows" that the file is only as long as it is.
All this works well as long as one process accesses a file. But in your case a process opened a file and wrote lots of bytes into it, making its length some big number in the "internal bookkeeping" of the OS. Now a second process (your shell command) truncated the file and but for the first program it is still as long as it was when it last added to it. If it tries to read something from further up (like when it tries to print the content) of course it will get garbage because what it reads is some random block on a disk which is not part of the file any more - but the program won't know that.
Log writing processes should therefore NOT write into log files continuously but open and close the log for every write action separately.
I hope this helps.
bakunin
This User Gave Thanks to bakunin For This Post:
10 More Discussions You Might Find Interesting
1. UNIX for Dummies Questions & Answers
If I wanted to redirect output to multiple log files, what would be the best way to do that?
echo "Unix is awesome" >>unixgod.log >>unixgod.log (3 Replies)
Discussion started by: darthur
3 Replies
2. UNIX for Dummies Questions & Answers
Solaris v5.6
What log files should be checked out as part of your sys admin daily routine?
I've printed out my syslog.conf file, and looked in /var/log and found authlog, syslog, and POPlog. I know of /var/adm/messages.
What others should I be looking for?
I know of the "find" command. I... (8 Replies)
Discussion started by: Westy564
8 Replies
3. UNIX for Dummies Questions & Answers
Hello,
I have a set of data (comma seperated) that I want to save to multiple files according to one of the fields in the data set.
I can easily do this with the following script:
BEGIN { FS = OFS = ","}
NF {print $0 >> ($2 "" ".csv")}
It works perfectly on a set of dummy data I have set... (8 Replies)
Discussion started by: pfft
8 Replies
4. Shell Programming and Scripting
Hey Guys,
I was wondering if someone would give me a hand with an issue I'm having, let me explain the situation:
I have a file that is constantly being written to and read from with updated lines:
# cat activity.file
activity1
activity2
activity3
activity4
activity5
This file... (2 Replies)
Discussion started by: bashshadow1979
2 Replies
5. Shell Programming and Scripting
How can view log messages between two time frame from /var/log/message or any type of log files.
when logfiles are very big and especially many messages with in few minutes, I would like to display log messages between 5 minute interval.
Could you pls give me the command? (1 Reply)
Discussion started by: johnveslin
1 Replies
6. Shell Programming and Scripting
we r to develope a project which involves automatic encryption of all the text files user was working upon during logg off
and to decrypt them during log on
this is to be done by writing a shell script
can anyone help (2 Replies)
Discussion started by: vyom
2 Replies
7. Shell Programming and Scripting
To delete log files content older than 30 days and append the lastest date log file date in the respective logs
I want to write a shell script that deletes all log files content older than 30 days and append the lastest log file date in the respective logs
This is my script
cd... (2 Replies)
Discussion started by: sreekumarhari
2 Replies
8. Shell Programming and Scripting
is there a way to efficiently monitor logfiles that do not have a date or time format? i have several logs on several different servers that need to be monitored. but i realized writing a script for this would be very complex and time consuming giving the variety of things i need to check for i.e.... (2 Replies)
Discussion started by: SkySmart
2 Replies
9. Shell Programming and Scripting
Hi Guys,
I am using set -x in my script to track the flow of the script.
But if i want to write the output of the set -x into a log file, how do i do it?
Thanks,
Ajay (3 Replies)
Discussion started by: Ajay Venkatesan
3 Replies
10. Shell Programming and Scripting
Hello Everyone,
I want to delete the image files from a directory, which are not listed in a TEXT file.
The directory contains large number of image files (in millions) required / not required. I want to delete the image files which are "not required".
I have generated a Text file having... (3 Replies)
Discussion started by: Praveen Pandit
3 Replies
LEARN ABOUT HPUX
vxcmdlog
vxcmdlog(1M) vxcmdlog(1M)
NAME
vxcmdlog - administer command logging
SYNOPSIS
vxcmdlog [-H] [-l] [-m {on|off}] [-n number] [-s size]
DESCRIPTION
The vxcmdlog command is used to administer command logging in Veritas Volume Manager (VxVM). This feature can be used to record all VxVM
commands that are issued, and can be used in conjunction with the transaction logging feature (see vxtranslog(1M)).
When the current log file reaches a maximum size, it is renamed as a historic log file, and a new current log file is created. A limited
number of historic log files is preserved to avoid filling up the file system.
Each log file contains a header that records the host name, host ID, and the date and time that the log was created. See the EXAMPLES sec-
tion below for a description of the entries that are recorded in a log file.
OPTIONS
-H Displays detailed help about the usage of the command.
-l Lists current settings for command logging. This shows whether command logging is enabled, the maximum number of historic log
files, and the maximum log file size.
-m {on|off}
Turns command logging on or off. By default, command logging is turned on.
-n number Sets the maximum number of historic log files to maintain. The default number is 5. If number is set to no_limit, there is no
limit on the number of historic log files that are created.
-s size Sets the maximum size to which a command log can grow. (Note that this setting has no effect on existing historic log files.)
The suffix modifiers k, m, and g may be used express sizes in kilobytes, megabytes and gigabytes respectively. If no suffix is
specified, the default units are kilobytes.
If size is set to no_limit, there is no limit on the size of the log file.
The size of the command log is checked after an entry has been written so the actual size may be slightly larger than that speci-
fied. When the log reaches the specified size, the current command log file, cmdlog, is renamed as the next available historic
log file, cmdlog.number, where number is an integer from 1 up to the maximum number of historic log files that is currently
defined.
If the maximum number of historic log files has been reached, the oldest historic log file is removed, and the current log file
is renamed as that file.
The default maximum size of the command log file is 1m(1MB).
EXAMPLES
Turn on command logging:
vxcmdlog -m on
Set the maximum command log file size to 512KB:
vxcmdlog -s 512k
Set the maximum number of historic command log files to 10:
vxcmdlog -n 10
The following are sample entries from a command log file:
/usr/sbin/vxdctl mode
/usr/sbin/vxdisk -q -o alldgs list
/etc/vx/diag.d/vxprivutil dumpconfig /dev/vx/rdmp/Disk_4s2
/usr/sbin/vxdisk list SENA0_1
Each entry usually contains a client ID that identifies the command connection to the vxconfigd daemon, the process ID of the command, a
time stamp, and the command that was used together with its arguments. If the client ID is 0, as in the third entry shown here, this means
that the command did not open a connection to vxconfigd.
Note: The client ID is the same as that recorded for the corresponding transactions in the transactions log.
FILES
/etc/vx/log Symbolic link to the log directory. This can be redefined if necessary.
/etc/vx/log/cmdlog Current command log.
/etc/vx/log/cmdlog.number
Historic command logs.
NOTES
If vxcmdlog records the invocation of a vxmake command that reads object definitions from a description file, vxcmdlog additionally records
the contents of the description file.
Most command scripts are not logged, but the command binaries that they call are logged. Exceptions are the vxdisksetup, vxinstall, and
vxdiskunsetup scripts, which are logged.
SEE ALSO
vxtranslog(1M)
Veritas Volume Manager Troubleshooting Guide
VxVM 5.0.31.1 24 Mar 2008 vxcmdlog(1M)