Hello all, just a quick little part of code i'm writing to check if the file i'm writing too in my automatic process is not being written too manually.
Code:
#!/bin/bash
FUSER=$(/sbin/fuser -s /toto.tmp >/dev/null 2>&1)
LSOF=$(/usr/sbin/lsof | grep -q "toto.tmp")
PGREP=$(pgrep -f "toto.tmp" > /dev/null )
# Manage error
error_log () {
printf "$(date '+%b %e %T') [ $1 ]: %-30s\n" "$2" | tee -a toto.log
}
check_if_open () {
echo FUSER: $FUSER
echo LSOF: $LSOF
echo PGREP: $PGREP
if [[ $FUSER -eq '0' ]] || [[ $LSOF -eq '0' ]] || [[ "X$PGREP" != "X" ]]; then
error_log "ERROR" "File toto.tmp is already in write mode"
else
echo nothing
fi
}
echo Start
check_if_open
echo END
The above code doesn't work and I know i could use something like this bellow but i'm sure there is an easier (cleaner) way.
Code:
pgrep -f "toto.tmp" > /dev/null
if [[ $? -eq '0' ]]; then
error_log blabla
fi
/usr/sbin/lsof | grep -q "toto.tmp"
if [[ $? -eq '0' ]]; then
error_log blablabla
fi
fuser...
if [[ $? -eq '0' ]]; then
error_log blablabla
fi
Thanks.
Last edited by maverick72; 06-11-2014 at 05:27 AM..
I need to write a function that will work in sh/ksh shell that will test to see if a file has already been opened for writting by another user
has anyone written something like this? (3 Replies)
To begin:
I use Linux
The Problem:
I need bcp functionality for scripts. Perl modules, such as Sybase:xfer, require ctlib which comes with Sybase Open Client. Talking with Sybase sales
reps is an exercise in futility and hate. They know absolutely nothing about their own products and will... (0 Replies)
I am out of idea what to do to resolve the problem!
I need to use the open(file, for.., access) function to write a file.
Never have the situation like that: it is return 0 - zero.
As a result all write(..) going to the screen!
What the problem it could be?
I do not even know... (2 Replies)
If a process already has the entire file locked for read and write using newstruct.l_type = F_WRLCK; what would happen if another process would try to open it in read only mode using open(filename, O_RDONLY); ?
I want to check if the file exists and I want it to work even if another process has... (4 Replies)
First post, sorry to be a bother but this one has been dogging me. I have a process user (java application server) that trips a resource limit every couple weeks and need help finding what limit we're hitting.
First, this is what's running:
This is the error when jobs are run or the... (0 Replies)
I know how to check if any file has a unix process using a file by looking at 'lsof <fullpath/filename>' command.
I think using lsof is very expensive. Also to make it accurate we need to inlcude fullpath of the file.
Is there another command that can tell if a file has a truely active... (12 Replies)
Hey all,
I'm brand new to script writing, I'm wanting to make a script that will ask for a file and then retrieve that file if it exists, and if it doesn't exist, create the file with the desired name, and I'm completely stuck.. so far..
#! bin/bash
echo "Enter desired file"
read "$file"
if ... (5 Replies)
Help Please perl Gurus,
I am trying to add ungrouped passengers in a group and I creating a script however it fails on first step only I tried all the options it returns following error.
syntax error at junki line 4, near "open "
Execution of junki aborted due to compilation errors. ... (2 Replies)
I am opening a text file using open() system call in O_RDONLY mode.
open() returns me a valid handler but also sets errno to 13 i.e. EACCES(Permission denied).
Question is when open() is returning a valid handler then why does it sets the errno?
Should not errno be set only in case of error... (10 Replies)
I have a script which does gunzip, zip and untar.
Input to the script is file name and file directory (where file is located)
I am reading the input parameters as follows:
FILENAME=$1
FILEDIR=$2
I have created 3 functions that are as follows:
1) gunzip file
2) unzip file... (2 Replies)
Discussion started by: pinnacle
2 Replies
LEARN ABOUT LINUX
lucancel
lucancel(1M) System Administration Commands lucancel(1M)NAME
lucancel - cancel a scheduled Live Upgrade copy/create procedure
SYNOPSIS
/usr/sbin/lucancel [-l error_log] [-o outfile] [-X]
DESCRIPTION
The lucancel command is part of a suite of commands that make up the Live Upgrade feature of the Solaris operating environment. See
live_upgrade(5) for a description of the Live Upgrade feature.
The lucancel command cancels a boot environment (BE) creation or upgrade that was scheduled in the FMLI-based interface, lu(1M), or the
repopulation of a BE, scheduled with lumake(1M). lucancel does not cancel a job that is active (that is, is in the process of creation or
repopulation).
The lucancel command requires root privileges.
OPTIONS
The lucancel command has the following options:
-l error_log
Error and status messages are sent to error_log, in addition to where they are sent in your current environment.
-o outfile
All command output is sent to outfile, in addition to where it is sent in your current environment.
-X
Enable XML output. Characteristics of XML are defined in DTD, in /usr/share/lib/xml/dtd/lu_cli.dtd.<num>, where <num> is the version
number of the DTD file.
EXIT STATUS
The following exit values are returned:
0 Successful completion.
>0 An error occurred.
FILES
/etc/lutab
list of BEs on the system
ATTRIBUTES
See attributes(5) for descriptions of the following attributes:
+-----------------------------+-----------------------------+
| ATTRIBUTE TYPE | ATTRIBUTE VALUE |
+-----------------------------+-----------------------------+
|Availability |SUNWluu |
+-----------------------------+-----------------------------+
SEE ALSO lu(1M), luactivate(1M), lucompare(1M), lucreate(1M), lucurr(1M), ludelete(1M), ludesc(1M), lufslist(1M), lumake(1M), lumount(1M), lure-
name(1M), lustatus(1M), luupgrade(1M), lutab(4), attributes(5), live_upgrade(5)SunOS 5.10 21 Dec 2001 lucancel(1M)