Still haven't mastered bash, not even a jack (
Have strung some command(s) together in /etc/cron.daily
#!/bin/bash ## Download no-bebug rawhide kernel /usr/bin/cd /var/cache/yum/x86_64/20/fedora-rawhide-kernel-nodebug-source/packages && \ /usr/bin/reposync --source -n =fedora-rawhide-kernel-nodebug kernel && \ ## used to rebuild new no-debug ## Rawhide kernels for non eol FedoraN /usr/local/bin/mock-kernel ---> (which is below question) Question: How do I prevent the above line from happening if nothing new was downloaded?
#!/bin/bash ## rebuild no-debug kernel using mock cd /etc/mock && \ /usr/bin/mock -r fedora-20-x86_64 --no-clean /var/cache/yum/x86_64/20/fedora-rawhide-kernel-nodebug-source/packages/*.rpm && \ /usr/bin/createrepo /var/lib/mock/fedora-20-x86_64/result && \ yum check-update && \ /usr/bin/mock -r mock -r fedora-19-x86_64 /var/cache/yum/x86_64/20/fedora-rawhide-kernel-nodebug-source/packages/kernel
</snipped F18>
On Sat, Sep 28, 2013 at 12:21 PM, Frank Murphy frankly3d@gmail.com wrote:
/usr/bin/cd
Without looking any further, this is clearly wrong. Even if there is a /usr/bin/cd file (see recent discussion) in order to have any effect on the current directory used by subsequent commands you *have* to use the Shell built-in cd.
poc
poc
On Sat, 28 Sep 2013 13:55:15 +0100 "Patrick O'Callaghan" pocallaghan@gmail.com wrote:
On Sat, Sep 28, 2013 at 12:21 PM, Frank Murphy frankly3d@gmail.com wrote:
/usr/bin/cd
Without looking any further, this is clearly wrong. Even if there is a /usr/bin/cd file (see recent discussion) in order to have any effect on the current directory used by subsequent commands you *have* to use the Shell built-in cd.
poc
I got around that by adding script to path, then "alias my_script=". my_script"
so it download where I need it.
On 28 Sep 2013, at 14:19, Frank Murphy frankly3d@gmail.com wrote:
On Sat, 28 Sep 2013 13:55:15 +0100 "Patrick O'Callaghan" pocallaghan@gmail.com wrote:
On Sat, Sep 28, 2013 at 12:21 PM, Frank Murphy frankly3d@gmail.com wrote:
/usr/bin/cd
Without looking any further, this is clearly wrong. Even if there is a /usr/bin/cd file (see recent discussion) in order to have any effect on the current directory used by subsequent commands you *have* to use the Shell built-in cd.
poc
I got around that by adding script to path, then "alias my_script=". my_script"
so it download where I need it.
-- Regards,
reposync -p dest-dir would be easier.
Junk
On Sat, 28 Sep 2013 14:27:57 +0100 Junk junk@therobinsonfamily.net wrote:
reposync -p dest-dir would be easier.
Junk
That's cleaner, but how do I stop the script if nothing to sync.
On Sat, Sep 28, 2013 at 6:21 AM, Frank Murphy frankly3d@gmail.com wrote:
Still haven't mastered bash, not even a jack (
Have strung some command(s) together in /etc/cron.daily
#!/bin/bash ## Download no-bebug rawhide kernel /usr/bin/cd /var/cache/yum/x86_64/20/fedora-rawhide-kernel-nodebug-source/packages && \ /usr/bin/reposync --source -n =fedora-rawhide-kernel-nodebug kernel && \ ## used to rebuild new no-debug ## Rawhide kernels for non eol FedoraN /usr/local/bin/mock-kernel ---> (which is below question) Question: How do I prevent the above line from happening if nothing new was downloaded?
While there might be a cleaner way to detect that something was downloaded what I do is log the output from reposync and then
if grep -q Download REPOSYNCLOG; then # do stuff when new things were synced fi
John
On Sat, 28 Sep 2013 10:31:07 -0500 inode0 inode0@gmail.com wrote:
While there might be a cleaner way to detect that something was downloaded what I do is log the output from reposync and then
if grep -q Download REPOSYNCLOG; then # do stuff when new things were synced fi
John
With bash would there be an else exit ?
Maybe me need to lookup bash functions :(
On Sat, Sep 28, 2013 at 11:30 AM, Frank Murphy frankly3d@gmail.com wrote:
On Sat, 28 Sep 2013 10:31:07 -0500 inode0 inode0@gmail.com wrote:
While there might be a cleaner way to detect that something was downloaded what I do is log the output from reposync and then
if grep -q Download REPOSYNCLOG; then # do stuff when new things were synced fi
John
With bash would there be an else exit ?
You can add one if you want one.
if something; then something else something else fi
John
hi frankly,
On 09/28/2013 11:30 AM, Frank Murphy wrote:
On Sat, 28 Sep 2013 10:31:07 -0500 inode0 inode0@gmail.com wrote:
While there might be a cleaner way to detect that something was downloaded what I do is log the output from reposync and then
if grep -q Download REPOSYNCLOG; then # do stuff when new things were synced fi
With bash would there be an else exit ?
frankly, no.
if the "if" fails, there is nothing else to do, so it will exit.
Maybe me need to lookup bash functions :(
frankly, would not hurt.
On Sat, 28 Sep 2013 10:31:07 -0500 inode0 inode0@gmail.com wrote:
On Sat, Sep 28, 2013 at 6:21 AM, Frank Murphy frankly3d@gmail.com wrote:
Still haven't mastered bash, not even a jack (
Have strung some command(s) together in /etc/cron.daily
#!/bin/bash ## Download no-bebug rawhide kernel /usr/bin/cd /var/cache/yum/x86_64/20/fedora-rawhide-kernel-nodebug-source/packages && \ /usr/bin/reposync --source -n =fedora-rawhide-kernel-nodebug kernel && \ ## used to rebuild new no-debug ## Rawhide kernels for non eol FedoraN /usr/local/bin/mock-kernel ---> (which is below question) Question: How do I prevent the above line from happening if nothing new was downloaded?
While there might be a cleaner way to detect that something was downloaded what I do is log the output from reposync and then
I decided to split it as two operations, using inotifywait on the watched dir. it would then kickin mock as required.
| > On Sat, Sep 28, 2013 at 6:21 AM, Frank Murphy frankly3d@gmail.com | > wrote: [...] | > > #!/bin/bash
Unless I really need bash, I use:
#!/bin/sh
More portable. You'll be surprised how little bash actually gives you in scripting scenarios.
| > > ## Download no-bebug rawhide kernel | > > /usr/bin/cd /var/cache/yum/x86_64/20/fedora-rawhide-kernel-nodebug-source/packages | > > && \ /usr/bin/reposync --source -n =fedora-rawhide-kernel-nodebug | > > kernel && \
Two remarks:
I tend to write lines like the above as:
cmd1 \ && cmd2
If you write:
cmd1 && \ cmd2
and accidentally put something after the slosh (such as some spaces), the former layout will cause a syntax error (alerting you) while the latter layout will quietly not work quite as expected.
Second:
I almost invariably put:
set -ue
at the top of my scripts. This turns on -u: abort on an undefined variable, VERY handy for catching assignment mistakes and -e: abort on error, which means abort when any command has a non-zero exit status _that has not been checked_.
This would let you write your script like this:
set -ue cd /var/cache/yum/x86_64/20/fedora-rawhide-kernel-nodebug-source/packages /usr/bin/reposync --source -n =fedora-rawhide-kernel-nodebug
and so on without all the tedious "&&" stuff.
It is surprisingly useful and easy to code under this regime, and catches a long of simple mistakes.
Cheers,