Scheduled Maintenance: We are aware of an issue with Google, AOL, and Yahoo services as email providers which are blocking new registrations. We are trying to fix the issue and we have several internal and external support tickets in process to resolve the issue. Please see: viewtopic.php?t=158230

 

 

 

Scripting:: passing variable between invocations

Programming languages, Coding, Executables, Package Creation, and Scripting.
Post Reply
Message
Author
alexpj
Posts: 38
Joined: 2006-07-04 23:30
Location: England

Scripting:: passing variable between invocations

#1 Post by alexpj »

Hello all and thank you for your attention (so far anyway!)
I used to program extensively in a variety of languages, but have not done anything for many years and now have lost my nerve.

I want to build on the code from /etc/apt/apt.conf.d/05etckeeper to work with Snapper, the new-in btrfs (et al) snapshot package.

Code: Select all

DPkg::Pre-Invoke       { "if [ -x /usr/bin/etckeeper ]; then etckeeper pre-install; fi"; };
DPkg::Post-Invoke      { "if [ -x /usr/bin/etckeeper ]; then etckeeper post-install; fi"; };
The etckeeper code will work well as a template, but I need to pass a parameter between the pre- and post- instances. The parameter is obtained from the pre- invocation and passed to the post- invocation.
I know that something similar to my quest is done with the 'pid' but I have no clue how to do it in the 'standard' way. Happily there can't be multiple dpkg instances running concurrently (prevented by dpkg?) so I don't have to worry about that issue.
Q1. Please, what is the 'standard' way of passing parameters about?

I hope to use:

Code: Select all

snapper -c etc create -t pre  -p     (which 'prints' the parameter (int) to pass to the following invocation)
snapper -c etc create -t post --pre-number  <parameter>  
in place of the two etckeeper calls.

I'd like to learn ruby, for lots of reasons, but if someone is kind enough to post shell-script or something I'll work the rest out!

Q2. Please, how do I pick up the 'printed' output of the 'pre' call? I think it's just a 'get' from the stream but perhaps I've missed something.?

Thank you in advance!

Oh and one final thing: before anyone says write a wrapper script for dpkg/apt/aptitude to avoid parameter passing, I'm doing it this way round as a learning exercise! ;-)

User avatar
saulgoode
Posts: 1445
Joined: 2007-10-22 11:34
Been thanked: 4 times

Re: Scripting:: passing variable between invocations

#2 Post by saulgoode »

A1. /var/tmp/ is generally used for variables (files) that should survive a reboot, /var/run/ for those that should not (e.g., a PID).

A2. You would typically redirect stdout (and/or stderr) to your "variable" file.
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it. -- Brian Kernighan

alexpj
Posts: 38
Joined: 2006-07-04 23:30
Location: England

Re: Scripting:: passing variable between invocations

#3 Post by alexpj »

saulgoode, gawd knows how I missed advice of your reply, I'm so sorry! :(
I was going to have a go at this again - I assumed that no one had replied at all - so thank you.

Post Reply