rake runs dependents when file already exists - rake

I thought by doing
file 'myfile' => [ :some_task ]
the task would not be run since the file already exists, but when the file does exist the task runs. So is there a way to have the task not run when the file exists?

It depends. what :some_task is.
:some_task is a Symbol, no String. It seems, myfile depends not on another file, but on a task.
If you have this situation:
require 'rake'
file 'myfile' => [ :some_task ] do |tsk|
puts "Start #{tsk}" #some action
end
task :some_task do |tsk|
puts "Start #{tsk}" #some action
end
the question if :some_task is newer, makes no sense. It is a task to be executed always.
And if myfile has a prerequsite, that must be executed, then myfile will be created.

Related

How can I call a taginfo batch script from cvsnt

I'd like to call a batch-script during a cvs tag operation on a cvsnt server. But everyting I get is "script execution failed". Where is the script I'd like to call supposed to be located or how could I address it with variables?
If I call shell commands directly like "echo something" everything works fine and I also get the additional parameters added by cvsnt like the actual TAG, command and directory. If I want to call a batch either with relative path, without a past or even with ${CVSROOT}/CVSROOT/triggerbuild.cmd everything I get is 'script execution failed'.
My taginfo entries:
ALL echo
-> results in tag command folder
ALL echo ${CVSROOT}/CVSROOT/trigger_release_build.bat
-> results in 'script execution failed'.
I want to simply call a batch script that trigger my jenkins server to start a build under some conditions. The trigger script is finished and working fine when executed from a local shell. Only integratino in cvsnt taginfo file doesn't work.
addition: the quoted Code is the overall code causing the failure. The code of the batch file is not relevant because it is not even called due to the error.
This is the documentation from cvsnt's tagfile:
# The "taginfo" file is used to control pre-tag checks.
# The filter on the right is invoked with the following arguments:
#
# $1 -- tagname
# $2 -- operation "add" for tag, "mov" for tag -F, and "del" for tag -d
# $3 -- repository
#
# The filter is passed a series of filename/version pairs on its standard input
#
# A non-zero exit of the filter program will cause the tag to be aborted.
#
# The first entry on a line is a regular expression which is tested
# against the directory that the change is being committed to, relative
# to the $CVSROOT. For the first match that is found, then the remainder
# of the line is the name of the filter to run.
#
# If the repository name does not match any of the regular expressions in this
# file, the "DEFAULT" line is used, if it is specified.
#
# If the name "ALL" appears as a regular expression it is always used
# in addition to the first matching regex or "DEFAULT".
When using backslashes I get different error messages about invalid characters \C

Lock clearcase label type using korn shell scripting

I am trying to lock the label type using korn shell script but I am not able to lock.
As I am new to Korn scripts can some one help me.
Here is my current code:
cmUsers="user1,user2";
myuserName=$ENV{LOGNAME};
#checking whether current user is part of cmUsers list or not.
if [[ "$cmUsers" =~ m/$myUserName/i ]]
# if user belongs to cmUsers list, then trying to lock the lable type,
# if it fails exiting the process, else printing the success message
"ct lock -nuser \"$cmUsers\" lbtype:${label}#/vobs/admin_rec" ;then
die"Unable to lock label type: \"${label}\"\n";
else
print "Label ${label} has been successfully locked by $cmUsers"
fi
Beside the shebang, one simple tip is to avoid using an alias (ct) in a script: use the full command cleartool instead.
See also "Ksh Scripting" and "ksh class"
#!/bin/ksh
cmUsers="user1,user2";
myuserName=$ENV{LOGNAME};
#checking whether current user is part of cmUsers list or not.
if [[ "$cmUsers" =~ m/$myUserName/i ]]; then
# if user belongs to cmUsers list, then trying to lock the lable type,
# if it fails exiting the process, else printing the success message
cleartool lock -nuser \"$cmUsers\" lbtype:${label}#/vobs/admin_rec"
if [ $? -ne 0 ]; then
echo "CRITICAL: Unable to lock label type: \"${label}\""
exit 1
fi
echo "Label ${label} has been successfully locked by $cmUsers"
fi
However, an expression like $ENV{LOGNAME} points to the fact it might not be ksh or any other shell, but rather ratperl (if you are using ClearCase 7.x or more): see "About ratlperl and its impact on cqperl and ccperl"
In which case, remove the shebang, and try executing your script with:
ccperl yourScript.pl

File delete action if condition exists

New to chef recipe and google is not showing me an example of what I need to do.
I have a file that I want deleted when chef finds it exists.
I am not finding any google examples of something like
file /path/foo do
action delete
end if /path/foo exists
and the chef file documentation is not showing anything like
file /path/foo do
condition exists
action delete
end
Is the only way to use a script like bash?
bash 'delete_foo' do
if [ -f /path/foo ] then
/bin/rm /path/foo
fi
end
file '/path/foo' do
action :delete
only_if { File.exist? '/path/foo' }
end

Shell Script execution of Perl code causing weird results

I have a cron job that runs several shell scripts:
30 1 * * 1-5 /ufs/00/home/usr/bin/ConsentforFoo.sh "prd"
15 1 * * 1-5 /ufs/00/home/usr/bin/apptTvoxforFoo.sh
the first shell script looks like this:
#!/bin/bash
# ConsentforFoo.sh - set different environments, set path to perl scripts, calls script
TMP_HOME=/home/localweb/htdocs/cgi-bin/usr/CFoodir
if [ "$1" = "dev" ] || [ "$1" = "uat" ] || [ "$1" = "prd" ]
then
cd $TMP_HOME/$1
My-Consent-Cron.pl
else
echo "Val Not Set: $1"
fi
this script works flawlessly... However, the second shell script looks like this:
#!/bin/bash
# apptTvoxforFoo.sh - sends MHT population and patients with multiple appointments to west
TMP_HOME=/home/localweb/htdocs/cgi-bin/usr/CFoodir
cd $TMP_HOME
TvoxCron.pl #adding './' works here
but when it runs, I get an error saying: "sh: /ufs/00/home/usr/bin/apptTvoxforFoo.sh: cannot execute"
I add a "pwd" to the shell script and it's getting in the right directory and the file is there...
Weirdest thing is when I add "./" to it, it works... but in the first shell script I don't have to...
Any ideas why taking the if/then/else out would force me to SOURCE the perl script?
Thanks for any help you can provide.
Did you check the file permissions on the directories and all the files? Can you add a dot in front of the file to make sure you are not finding the file on the path?
./TvoxCron.pl

rake directory command silently fails?

I'm a newbie to rake so there's probably a simple explanation. I wanted to create some directories and copy in some files for a simple install script e.g.
task :default => ['mktd1', 'mktd2' ] do
end
task :mktd1 do
mkdir "testdata"
cp "x.tmp", "testdata/x.tmp"
end
task :mktd2 do
directory "testdata1"
cp "x.tmp", "testdata1/x.tmp"
end
mkdir works as long as the testdata directory doesnt already exist, but "directory" silently fails (i.e. does nothing) leading to a rake abort because the directory isn't there for the cp command.
Have I misunderstood what directory directive is supposed to do?
So the answer was I had misunderstood how rake is supposed to work. To achieve what I wanted I needed to declare a task that had a dependency on the testdata1 directory. e.g.
task :default => [ 'testdata1/x.tmp' ] do
end
directory "testdata1"
file "testdata1/x.tmp" => ["testdata1"] do
cp "x.tmp", "testdata1/x.tmp"
end
This of course creates a file_creation task x.tmp which depends on the testdata1 directory, and a default task that depends on the x.tmp file creation task. I feel dumb.