I'm trying to create a simple bash shell script provisioner for a vagrant puppet dev env which checks that /tmp/puppet-modules-up-to-date exists and was created within a certain timeframe, 14 days to be precise. I'm struggling to progress with this simple script. Any help appreciated.
#!/bin/bash
if [[ ! -f /tmp/.puppet-modules-up-to-date ]] && [[ ! (find /tmp/.puppet-modules-up-to-date -mtime -14 | grep puppet) ]]; then
puppet_dir=/etc/puppet
echo 'Copying Puppetfile into place'
cp /vagrant/puppet/Puppetfile $puppet_dir
cd $puppet_dir
echo 'Installing puppet modules into place'
librarian-puppet install
echo 'Updating previously installed puppet modules'
librarian-puppet update
touch /tmp/.puppet-modules-up-to-date
fi
Simply gives me the following error:
==> default: /tmp/vagrant-shell: line 3: conditional binary operator expected
==> default: /tmp/vagrant-shell: line 3: expected `)'
==> default: /tmp/vagrant-shell: line 3: syntax error near `/tmp/.puppet-modules-up-to-date'
==> default: /tmp/vagrant-shell: line 3: `if [[ ! -f /tmp/.puppet-modules-up-to-date ]] && [[ ! (find /tmp/.puppet-modules-up-to-date -mtime -14 | grep puppet) ]]; then'
Problem seems to be here:
[[ ! (find /tmp/.puppet-modules-up-to-date -mtime -14 | grep puppet) ]];
Since this is not really catching output of find/grep
which you could do using $(find...)
command.
However you can handle this condition better using grep -q
:
find /tmp/.puppet-modules-up-to-date -mtime -14 | grep -vq puppet
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.