How to make my script wait if another instance of APT is running? [on hold]
I've encouter some problems with my scripts.
So to make it short and clear, I'm in an internship and my boss gave me an assignement to make a Probe for Nagios.
The purpose of this Probe is to check on all our hosts if a package is missing from the repo if yes then we have a Warning on Nagios with the list of missing packages.
This Probe can include a Whitelist if we want to keep a package which is not in whatever repo but we're not using it.
Here is my script:
#!/bin/bash
STATE_OK=0
STATE_WARNING=1
STATE_CRITICAL=2
which apt-show-versions >/dev/null
STATE=$?
declare -a WHITELIST=( host1:elasticsearch:all host2:elasticsearch:all)
PACKAGES=()
NOT_AVAILABLE=()
HOST=$(hostname)
#while [ -f /var/lib/apt/lists/lock ]
#do
# sleep 2
#done
if [ "$STATE" = 0 ] #Verifie la condition apt-show-version = installer
then
packets=$(apt-show-versions | grep 'No available version in archive' | cut -d" " -f1)
for packet in $packets;do
PACKAGES+=("${HOST}:$packet")
done
for package in "${PACKAGES[@]}"; do
if [ "${WHITELIST[*]}" != "${package}" ]; then
NOT_AVAILABLE+=("$package")
fi
done
if [ -z "$NOT_AVAILABLE" ]; then
#Ok dans Nagios
echo "There is no package without version in archive"
exit $STATE_OK
else
#Warning dans Nagios
echo "Some package have no available version in archive"
echo ${NOT_AVAILABLE[*]//"${HOST}":}
exit $STATE_WARNING
fi
else
#Critical dans nagios
echo "Package apt-show-versions is missing"
exit $STATE_CRITICAL
fi
And there is the message that is coming frome Nagios :
Remote command execution failed: Failed to open file /var/lib/apt/lists//security.debian.org_dists_stretch_updates_InRelease for reading: Permission denied
I tried to play with lock file in my script but it doesn't work, I got like an infinite loop.
I already gave a look at this question
and tried to make a wrapper but he didn't worked or I missed something since I'm student and this is my first step in the shell scripting world.
I looked at this, too but it's kinda old.
apt bash package-management scripts nagios3
New contributor
put on hold as off-topic by Thomas Ward♦ Jan 22 at 16:17
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "This is not about Ubuntu. Questions about other Linux distributions can be asked on Unix & Linux, those about Windows on Super User, those about Apple products on Ask Different and generic programming questions on Stack Overflow." – Thomas Ward
If this question can be reworded to fit the rules in the help center, please edit the question.
add a comment |
I've encouter some problems with my scripts.
So to make it short and clear, I'm in an internship and my boss gave me an assignement to make a Probe for Nagios.
The purpose of this Probe is to check on all our hosts if a package is missing from the repo if yes then we have a Warning on Nagios with the list of missing packages.
This Probe can include a Whitelist if we want to keep a package which is not in whatever repo but we're not using it.
Here is my script:
#!/bin/bash
STATE_OK=0
STATE_WARNING=1
STATE_CRITICAL=2
which apt-show-versions >/dev/null
STATE=$?
declare -a WHITELIST=( host1:elasticsearch:all host2:elasticsearch:all)
PACKAGES=()
NOT_AVAILABLE=()
HOST=$(hostname)
#while [ -f /var/lib/apt/lists/lock ]
#do
# sleep 2
#done
if [ "$STATE" = 0 ] #Verifie la condition apt-show-version = installer
then
packets=$(apt-show-versions | grep 'No available version in archive' | cut -d" " -f1)
for packet in $packets;do
PACKAGES+=("${HOST}:$packet")
done
for package in "${PACKAGES[@]}"; do
if [ "${WHITELIST[*]}" != "${package}" ]; then
NOT_AVAILABLE+=("$package")
fi
done
if [ -z "$NOT_AVAILABLE" ]; then
#Ok dans Nagios
echo "There is no package without version in archive"
exit $STATE_OK
else
#Warning dans Nagios
echo "Some package have no available version in archive"
echo ${NOT_AVAILABLE[*]//"${HOST}":}
exit $STATE_WARNING
fi
else
#Critical dans nagios
echo "Package apt-show-versions is missing"
exit $STATE_CRITICAL
fi
And there is the message that is coming frome Nagios :
Remote command execution failed: Failed to open file /var/lib/apt/lists//security.debian.org_dists_stretch_updates_InRelease for reading: Permission denied
I tried to play with lock file in my script but it doesn't work, I got like an infinite loop.
I already gave a look at this question
and tried to make a wrapper but he didn't worked or I missed something since I'm student and this is my first step in the shell scripting world.
I looked at this, too but it's kinda old.
apt bash package-management scripts nagios3
New contributor
put on hold as off-topic by Thomas Ward♦ Jan 22 at 16:17
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "This is not about Ubuntu. Questions about other Linux distributions can be asked on Unix & Linux, those about Windows on Super User, those about Apple products on Ask Different and generic programming questions on Stack Overflow." – Thomas Ward
If this question can be reworded to fit the rules in the help center, please edit the question.
What about this answer on your first linked question ? askubuntu.com/a/373478/631600, this seems to work for me.
– RoVo
Jan 21 at 14:31
1
btw: Debian questions should be posted at U&L
– RoVo
Jan 21 at 14:33
@RoVo My bad I'm used to check on ask ubuntu since at school we have ubuntu, I will check or post my next question about Debian on unix.stackexchange.com in the future.
– Ghrew
Jan 21 at 14:38
1
You don't need to make apt wait at all. You are just querying apt's cache (database), not doing package actions. Use theapt-cache
command. Package actions can be queued using aptdaemon, but that can be complex to use.
– user535733
Jan 21 at 18:29
Nitpicking about terminology: Throughout the script use the word package, not packet. A packet is something else.
– kasperd
Jan 21 at 19:58
add a comment |
I've encouter some problems with my scripts.
So to make it short and clear, I'm in an internship and my boss gave me an assignement to make a Probe for Nagios.
The purpose of this Probe is to check on all our hosts if a package is missing from the repo if yes then we have a Warning on Nagios with the list of missing packages.
This Probe can include a Whitelist if we want to keep a package which is not in whatever repo but we're not using it.
Here is my script:
#!/bin/bash
STATE_OK=0
STATE_WARNING=1
STATE_CRITICAL=2
which apt-show-versions >/dev/null
STATE=$?
declare -a WHITELIST=( host1:elasticsearch:all host2:elasticsearch:all)
PACKAGES=()
NOT_AVAILABLE=()
HOST=$(hostname)
#while [ -f /var/lib/apt/lists/lock ]
#do
# sleep 2
#done
if [ "$STATE" = 0 ] #Verifie la condition apt-show-version = installer
then
packets=$(apt-show-versions | grep 'No available version in archive' | cut -d" " -f1)
for packet in $packets;do
PACKAGES+=("${HOST}:$packet")
done
for package in "${PACKAGES[@]}"; do
if [ "${WHITELIST[*]}" != "${package}" ]; then
NOT_AVAILABLE+=("$package")
fi
done
if [ -z "$NOT_AVAILABLE" ]; then
#Ok dans Nagios
echo "There is no package without version in archive"
exit $STATE_OK
else
#Warning dans Nagios
echo "Some package have no available version in archive"
echo ${NOT_AVAILABLE[*]//"${HOST}":}
exit $STATE_WARNING
fi
else
#Critical dans nagios
echo "Package apt-show-versions is missing"
exit $STATE_CRITICAL
fi
And there is the message that is coming frome Nagios :
Remote command execution failed: Failed to open file /var/lib/apt/lists//security.debian.org_dists_stretch_updates_InRelease for reading: Permission denied
I tried to play with lock file in my script but it doesn't work, I got like an infinite loop.
I already gave a look at this question
and tried to make a wrapper but he didn't worked or I missed something since I'm student and this is my first step in the shell scripting world.
I looked at this, too but it's kinda old.
apt bash package-management scripts nagios3
New contributor
I've encouter some problems with my scripts.
So to make it short and clear, I'm in an internship and my boss gave me an assignement to make a Probe for Nagios.
The purpose of this Probe is to check on all our hosts if a package is missing from the repo if yes then we have a Warning on Nagios with the list of missing packages.
This Probe can include a Whitelist if we want to keep a package which is not in whatever repo but we're not using it.
Here is my script:
#!/bin/bash
STATE_OK=0
STATE_WARNING=1
STATE_CRITICAL=2
which apt-show-versions >/dev/null
STATE=$?
declare -a WHITELIST=( host1:elasticsearch:all host2:elasticsearch:all)
PACKAGES=()
NOT_AVAILABLE=()
HOST=$(hostname)
#while [ -f /var/lib/apt/lists/lock ]
#do
# sleep 2
#done
if [ "$STATE" = 0 ] #Verifie la condition apt-show-version = installer
then
packets=$(apt-show-versions | grep 'No available version in archive' | cut -d" " -f1)
for packet in $packets;do
PACKAGES+=("${HOST}:$packet")
done
for package in "${PACKAGES[@]}"; do
if [ "${WHITELIST[*]}" != "${package}" ]; then
NOT_AVAILABLE+=("$package")
fi
done
if [ -z "$NOT_AVAILABLE" ]; then
#Ok dans Nagios
echo "There is no package without version in archive"
exit $STATE_OK
else
#Warning dans Nagios
echo "Some package have no available version in archive"
echo ${NOT_AVAILABLE[*]//"${HOST}":}
exit $STATE_WARNING
fi
else
#Critical dans nagios
echo "Package apt-show-versions is missing"
exit $STATE_CRITICAL
fi
And there is the message that is coming frome Nagios :
Remote command execution failed: Failed to open file /var/lib/apt/lists//security.debian.org_dists_stretch_updates_InRelease for reading: Permission denied
I tried to play with lock file in my script but it doesn't work, I got like an infinite loop.
I already gave a look at this question
and tried to make a wrapper but he didn't worked or I missed something since I'm student and this is my first step in the shell scripting world.
I looked at this, too but it's kinda old.
apt bash package-management scripts nagios3
apt bash package-management scripts nagios3
New contributor
New contributor
edited Jan 21 at 14:36
Mr Shunz
2,40521922
2,40521922
New contributor
asked Jan 21 at 14:21
GhrewGhrew
211
211
New contributor
New contributor
put on hold as off-topic by Thomas Ward♦ Jan 22 at 16:17
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "This is not about Ubuntu. Questions about other Linux distributions can be asked on Unix & Linux, those about Windows on Super User, those about Apple products on Ask Different and generic programming questions on Stack Overflow." – Thomas Ward
If this question can be reworded to fit the rules in the help center, please edit the question.
put on hold as off-topic by Thomas Ward♦ Jan 22 at 16:17
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "This is not about Ubuntu. Questions about other Linux distributions can be asked on Unix & Linux, those about Windows on Super User, those about Apple products on Ask Different and generic programming questions on Stack Overflow." – Thomas Ward
If this question can be reworded to fit the rules in the help center, please edit the question.
What about this answer on your first linked question ? askubuntu.com/a/373478/631600, this seems to work for me.
– RoVo
Jan 21 at 14:31
1
btw: Debian questions should be posted at U&L
– RoVo
Jan 21 at 14:33
@RoVo My bad I'm used to check on ask ubuntu since at school we have ubuntu, I will check or post my next question about Debian on unix.stackexchange.com in the future.
– Ghrew
Jan 21 at 14:38
1
You don't need to make apt wait at all. You are just querying apt's cache (database), not doing package actions. Use theapt-cache
command. Package actions can be queued using aptdaemon, but that can be complex to use.
– user535733
Jan 21 at 18:29
Nitpicking about terminology: Throughout the script use the word package, not packet. A packet is something else.
– kasperd
Jan 21 at 19:58
add a comment |
What about this answer on your first linked question ? askubuntu.com/a/373478/631600, this seems to work for me.
– RoVo
Jan 21 at 14:31
1
btw: Debian questions should be posted at U&L
– RoVo
Jan 21 at 14:33
@RoVo My bad I'm used to check on ask ubuntu since at school we have ubuntu, I will check or post my next question about Debian on unix.stackexchange.com in the future.
– Ghrew
Jan 21 at 14:38
1
You don't need to make apt wait at all. You are just querying apt's cache (database), not doing package actions. Use theapt-cache
command. Package actions can be queued using aptdaemon, but that can be complex to use.
– user535733
Jan 21 at 18:29
Nitpicking about terminology: Throughout the script use the word package, not packet. A packet is something else.
– kasperd
Jan 21 at 19:58
What about this answer on your first linked question ? askubuntu.com/a/373478/631600, this seems to work for me.
– RoVo
Jan 21 at 14:31
What about this answer on your first linked question ? askubuntu.com/a/373478/631600, this seems to work for me.
– RoVo
Jan 21 at 14:31
1
1
btw: Debian questions should be posted at U&L
– RoVo
Jan 21 at 14:33
btw: Debian questions should be posted at U&L
– RoVo
Jan 21 at 14:33
@RoVo My bad I'm used to check on ask ubuntu since at school we have ubuntu, I will check or post my next question about Debian on unix.stackexchange.com in the future.
– Ghrew
Jan 21 at 14:38
@RoVo My bad I'm used to check on ask ubuntu since at school we have ubuntu, I will check or post my next question about Debian on unix.stackexchange.com in the future.
– Ghrew
Jan 21 at 14:38
1
1
You don't need to make apt wait at all. You are just querying apt's cache (database), not doing package actions. Use the
apt-cache
command. Package actions can be queued using aptdaemon, but that can be complex to use.– user535733
Jan 21 at 18:29
You don't need to make apt wait at all. You are just querying apt's cache (database), not doing package actions. Use the
apt-cache
command. Package actions can be queued using aptdaemon, but that can be complex to use.– user535733
Jan 21 at 18:29
Nitpicking about terminology: Throughout the script use the word package, not packet. A packet is something else.
– kasperd
Jan 21 at 19:58
Nitpicking about terminology: Throughout the script use the word package, not packet. A packet is something else.
– kasperd
Jan 21 at 19:58
add a comment |
1 Answer
1
active
oldest
votes
Consider using lsof
to check if the file is in use, as recommended on related Serverfault post. You could do something like this:
while [ "x$(lsof /var/lib/apt/lists/lock)" != "x" ] ; do
# if lsof returns output, that means some apt task is running
# wait 60 seconds and check again
sleep 60
done
Another command would be fuser
(and IMHO better than lsof
). According to documentation:
fuser returns a non-zero return code if none of the specified files is accessed or in case of a fatal error. If at least one access has been found, fuser returns zero.
This means you can rely on exit status in the loop, which makes the syntax nicer:
while fuser /var/lib/apt/lists/lock > /dev/null ; do
sleep 60
done
Ideally, you probably should use fnctl()
type of function to see if file is locked, either via C or Python.
See also:
- Is there a faster way to check if a file is in use?
Ok thank you I will try that.
– Ghrew
Jan 21 at 14:43
The lock file is not supposed to get (got (?)) deleted after apt-get has finish his thing ? There is something I don't understant : /
– Ghrew
Jan 21 at 15:10
@Ghrew Not necessarily. The whole point of is to make file inaccessible, thus preventing a process from writing to file or obtaining another lock on the file; this in effect serves as a sign that there's another process using a file, or in this case - there exists another instance of the program. In C it's done viaflock()
syscall, and there's a shell utility.
– Sergiy Kolodyazhnyy
Jan 21 at 15:16
Well I tried to make some changes but looking for the lock file was dumb, since this file will not be deleted by apt or the others scripts that use apt after their jobs is done. My boss gave me something to think about this morning like using flock or use a "hook" to do something like : apt-show-versions > /tmp/ghrew-nagios-apt-show-versions but I never made a hook or know what is a hook, I will make some research and come back to let u know how it goes
– Ghrew
2 days ago
@Ghrew Usually that file isn't deleted, unless a privileged user does it (and sometimes there are cases IIRC where you might have to do it), so it's by design like that. Tryflock
utility, but you'll need to run that withsudo
. Let me know how that goes
– Sergiy Kolodyazhnyy
2 days ago
|
show 1 more comment
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Consider using lsof
to check if the file is in use, as recommended on related Serverfault post. You could do something like this:
while [ "x$(lsof /var/lib/apt/lists/lock)" != "x" ] ; do
# if lsof returns output, that means some apt task is running
# wait 60 seconds and check again
sleep 60
done
Another command would be fuser
(and IMHO better than lsof
). According to documentation:
fuser returns a non-zero return code if none of the specified files is accessed or in case of a fatal error. If at least one access has been found, fuser returns zero.
This means you can rely on exit status in the loop, which makes the syntax nicer:
while fuser /var/lib/apt/lists/lock > /dev/null ; do
sleep 60
done
Ideally, you probably should use fnctl()
type of function to see if file is locked, either via C or Python.
See also:
- Is there a faster way to check if a file is in use?
Ok thank you I will try that.
– Ghrew
Jan 21 at 14:43
The lock file is not supposed to get (got (?)) deleted after apt-get has finish his thing ? There is something I don't understant : /
– Ghrew
Jan 21 at 15:10
@Ghrew Not necessarily. The whole point of is to make file inaccessible, thus preventing a process from writing to file or obtaining another lock on the file; this in effect serves as a sign that there's another process using a file, or in this case - there exists another instance of the program. In C it's done viaflock()
syscall, and there's a shell utility.
– Sergiy Kolodyazhnyy
Jan 21 at 15:16
Well I tried to make some changes but looking for the lock file was dumb, since this file will not be deleted by apt or the others scripts that use apt after their jobs is done. My boss gave me something to think about this morning like using flock or use a "hook" to do something like : apt-show-versions > /tmp/ghrew-nagios-apt-show-versions but I never made a hook or know what is a hook, I will make some research and come back to let u know how it goes
– Ghrew
2 days ago
@Ghrew Usually that file isn't deleted, unless a privileged user does it (and sometimes there are cases IIRC where you might have to do it), so it's by design like that. Tryflock
utility, but you'll need to run that withsudo
. Let me know how that goes
– Sergiy Kolodyazhnyy
2 days ago
|
show 1 more comment
Consider using lsof
to check if the file is in use, as recommended on related Serverfault post. You could do something like this:
while [ "x$(lsof /var/lib/apt/lists/lock)" != "x" ] ; do
# if lsof returns output, that means some apt task is running
# wait 60 seconds and check again
sleep 60
done
Another command would be fuser
(and IMHO better than lsof
). According to documentation:
fuser returns a non-zero return code if none of the specified files is accessed or in case of a fatal error. If at least one access has been found, fuser returns zero.
This means you can rely on exit status in the loop, which makes the syntax nicer:
while fuser /var/lib/apt/lists/lock > /dev/null ; do
sleep 60
done
Ideally, you probably should use fnctl()
type of function to see if file is locked, either via C or Python.
See also:
- Is there a faster way to check if a file is in use?
Ok thank you I will try that.
– Ghrew
Jan 21 at 14:43
The lock file is not supposed to get (got (?)) deleted after apt-get has finish his thing ? There is something I don't understant : /
– Ghrew
Jan 21 at 15:10
@Ghrew Not necessarily. The whole point of is to make file inaccessible, thus preventing a process from writing to file or obtaining another lock on the file; this in effect serves as a sign that there's another process using a file, or in this case - there exists another instance of the program. In C it's done viaflock()
syscall, and there's a shell utility.
– Sergiy Kolodyazhnyy
Jan 21 at 15:16
Well I tried to make some changes but looking for the lock file was dumb, since this file will not be deleted by apt or the others scripts that use apt after their jobs is done. My boss gave me something to think about this morning like using flock or use a "hook" to do something like : apt-show-versions > /tmp/ghrew-nagios-apt-show-versions but I never made a hook or know what is a hook, I will make some research and come back to let u know how it goes
– Ghrew
2 days ago
@Ghrew Usually that file isn't deleted, unless a privileged user does it (and sometimes there are cases IIRC where you might have to do it), so it's by design like that. Tryflock
utility, but you'll need to run that withsudo
. Let me know how that goes
– Sergiy Kolodyazhnyy
2 days ago
|
show 1 more comment
Consider using lsof
to check if the file is in use, as recommended on related Serverfault post. You could do something like this:
while [ "x$(lsof /var/lib/apt/lists/lock)" != "x" ] ; do
# if lsof returns output, that means some apt task is running
# wait 60 seconds and check again
sleep 60
done
Another command would be fuser
(and IMHO better than lsof
). According to documentation:
fuser returns a non-zero return code if none of the specified files is accessed or in case of a fatal error. If at least one access has been found, fuser returns zero.
This means you can rely on exit status in the loop, which makes the syntax nicer:
while fuser /var/lib/apt/lists/lock > /dev/null ; do
sleep 60
done
Ideally, you probably should use fnctl()
type of function to see if file is locked, either via C or Python.
See also:
- Is there a faster way to check if a file is in use?
Consider using lsof
to check if the file is in use, as recommended on related Serverfault post. You could do something like this:
while [ "x$(lsof /var/lib/apt/lists/lock)" != "x" ] ; do
# if lsof returns output, that means some apt task is running
# wait 60 seconds and check again
sleep 60
done
Another command would be fuser
(and IMHO better than lsof
). According to documentation:
fuser returns a non-zero return code if none of the specified files is accessed or in case of a fatal error. If at least one access has been found, fuser returns zero.
This means you can rely on exit status in the loop, which makes the syntax nicer:
while fuser /var/lib/apt/lists/lock > /dev/null ; do
sleep 60
done
Ideally, you probably should use fnctl()
type of function to see if file is locked, either via C or Python.
See also:
- Is there a faster way to check if a file is in use?
answered Jan 21 at 14:35
Sergiy KolodyazhnyySergiy Kolodyazhnyy
71.5k9147313
71.5k9147313
Ok thank you I will try that.
– Ghrew
Jan 21 at 14:43
The lock file is not supposed to get (got (?)) deleted after apt-get has finish his thing ? There is something I don't understant : /
– Ghrew
Jan 21 at 15:10
@Ghrew Not necessarily. The whole point of is to make file inaccessible, thus preventing a process from writing to file or obtaining another lock on the file; this in effect serves as a sign that there's another process using a file, or in this case - there exists another instance of the program. In C it's done viaflock()
syscall, and there's a shell utility.
– Sergiy Kolodyazhnyy
Jan 21 at 15:16
Well I tried to make some changes but looking for the lock file was dumb, since this file will not be deleted by apt or the others scripts that use apt after their jobs is done. My boss gave me something to think about this morning like using flock or use a "hook" to do something like : apt-show-versions > /tmp/ghrew-nagios-apt-show-versions but I never made a hook or know what is a hook, I will make some research and come back to let u know how it goes
– Ghrew
2 days ago
@Ghrew Usually that file isn't deleted, unless a privileged user does it (and sometimes there are cases IIRC where you might have to do it), so it's by design like that. Tryflock
utility, but you'll need to run that withsudo
. Let me know how that goes
– Sergiy Kolodyazhnyy
2 days ago
|
show 1 more comment
Ok thank you I will try that.
– Ghrew
Jan 21 at 14:43
The lock file is not supposed to get (got (?)) deleted after apt-get has finish his thing ? There is something I don't understant : /
– Ghrew
Jan 21 at 15:10
@Ghrew Not necessarily. The whole point of is to make file inaccessible, thus preventing a process from writing to file or obtaining another lock on the file; this in effect serves as a sign that there's another process using a file, or in this case - there exists another instance of the program. In C it's done viaflock()
syscall, and there's a shell utility.
– Sergiy Kolodyazhnyy
Jan 21 at 15:16
Well I tried to make some changes but looking for the lock file was dumb, since this file will not be deleted by apt or the others scripts that use apt after their jobs is done. My boss gave me something to think about this morning like using flock or use a "hook" to do something like : apt-show-versions > /tmp/ghrew-nagios-apt-show-versions but I never made a hook or know what is a hook, I will make some research and come back to let u know how it goes
– Ghrew
2 days ago
@Ghrew Usually that file isn't deleted, unless a privileged user does it (and sometimes there are cases IIRC where you might have to do it), so it's by design like that. Tryflock
utility, but you'll need to run that withsudo
. Let me know how that goes
– Sergiy Kolodyazhnyy
2 days ago
Ok thank you I will try that.
– Ghrew
Jan 21 at 14:43
Ok thank you I will try that.
– Ghrew
Jan 21 at 14:43
The lock file is not supposed to get (got (?)) deleted after apt-get has finish his thing ? There is something I don't understant : /
– Ghrew
Jan 21 at 15:10
The lock file is not supposed to get (got (?)) deleted after apt-get has finish his thing ? There is something I don't understant : /
– Ghrew
Jan 21 at 15:10
@Ghrew Not necessarily. The whole point of is to make file inaccessible, thus preventing a process from writing to file or obtaining another lock on the file; this in effect serves as a sign that there's another process using a file, or in this case - there exists another instance of the program. In C it's done via
flock()
syscall, and there's a shell utility.– Sergiy Kolodyazhnyy
Jan 21 at 15:16
@Ghrew Not necessarily. The whole point of is to make file inaccessible, thus preventing a process from writing to file or obtaining another lock on the file; this in effect serves as a sign that there's another process using a file, or in this case - there exists another instance of the program. In C it's done via
flock()
syscall, and there's a shell utility.– Sergiy Kolodyazhnyy
Jan 21 at 15:16
Well I tried to make some changes but looking for the lock file was dumb, since this file will not be deleted by apt or the others scripts that use apt after their jobs is done. My boss gave me something to think about this morning like using flock or use a "hook" to do something like : apt-show-versions > /tmp/ghrew-nagios-apt-show-versions but I never made a hook or know what is a hook, I will make some research and come back to let u know how it goes
– Ghrew
2 days ago
Well I tried to make some changes but looking for the lock file was dumb, since this file will not be deleted by apt or the others scripts that use apt after their jobs is done. My boss gave me something to think about this morning like using flock or use a "hook" to do something like : apt-show-versions > /tmp/ghrew-nagios-apt-show-versions but I never made a hook or know what is a hook, I will make some research and come back to let u know how it goes
– Ghrew
2 days ago
@Ghrew Usually that file isn't deleted, unless a privileged user does it (and sometimes there are cases IIRC where you might have to do it), so it's by design like that. Try
flock
utility, but you'll need to run that with sudo
. Let me know how that goes– Sergiy Kolodyazhnyy
2 days ago
@Ghrew Usually that file isn't deleted, unless a privileged user does it (and sometimes there are cases IIRC where you might have to do it), so it's by design like that. Try
flock
utility, but you'll need to run that with sudo
. Let me know how that goes– Sergiy Kolodyazhnyy
2 days ago
|
show 1 more comment
What about this answer on your first linked question ? askubuntu.com/a/373478/631600, this seems to work for me.
– RoVo
Jan 21 at 14:31
1
btw: Debian questions should be posted at U&L
– RoVo
Jan 21 at 14:33
@RoVo My bad I'm used to check on ask ubuntu since at school we have ubuntu, I will check or post my next question about Debian on unix.stackexchange.com in the future.
– Ghrew
Jan 21 at 14:38
1
You don't need to make apt wait at all. You are just querying apt's cache (database), not doing package actions. Use the
apt-cache
command. Package actions can be queued using aptdaemon, but that can be complex to use.– user535733
Jan 21 at 18:29
Nitpicking about terminology: Throughout the script use the word package, not packet. A packet is something else.
– kasperd
Jan 21 at 19:58