We would like Teamcity to build our solutions on every commit into subversion.
Following the documentation, we are to create a .sh script :-
SERVER=https://buildserver-url
USER=buildserver-user
PASS="<password>"
LOCATOR=$1
# The following is one-line:
(sleep 10; curl --user $USER:$PASS -X POST "$SERVER/app/rest/vcs-root-instances/commitHookNotification?locator=$LOCATOR" -o /dev/null) >/dev/null 2>&1 <&1 &
exit 0
Subversion is running on a windows environment, and so the .sh file will fail.
We are trying to convert this into a .bat file of which we have :-
set SERVER=https://buildserver-url
set USER=buildserver
set PASS=password
LOCATOR=%1%
(timeout 10; curl --user %USER%:%PASS% -X POST "%SERVER%/app/rest/vcs-root-instances/commitHookNotification?locator=%LOCATOR%" -o /dev/null) >/dev/null 2>%1% <%1% &
exit 0
However, this is still failing when trying to execute with
"The system cannot find the path specified"
It seems that perhaps we havnt converted this correctly?
Are the programs you're referencing (such as curl and timeout.exe) in locations that are present in the $PATH/%PATH% variable? How about any other files you're referencing - are you specifying full paths
Side note: Did you install curl and timeout.exe on the Windows server?
Also, /dev/null does not exist on Windows; you need to redirect to NUL. You can't just change the file extension and some of your syntax and expect a bash script to work on Windows.
Were I in your shoes, I'd skip batch altogether and write the script in something modern and sane like Powershell.
Related
I'm trying to learn how to code. I have to say that I'm using the Ubuntu app on the Windows system, so I don't know if my problems are related to this system.
I established these variables in the terminal
FOLDER="/mnt/c/Users/franc/Desktop/nuova"
species=mm10
fragmentsize=200
window=200
gap=200
output="/mnt/c/Users/franc/Desktop/nuova/sicer"
and then I wrote this loop
#!/bin/bash
for fq in $FOLDER/*.bam
do
bedtools bamtobed -i "$fq" > "${fq%.bam}.bed"
sicer -t ${fq%.bam}.bed \
-s $species \
-f $fragmentsize \
-w $window \
-g $gap \
-o $output
echo "DONE"
done
Basically I want the files in the FOLDER to be transformed in "${fq%.bam}.bed" and then I want to run sicer tool on these new files.
If I copy and paste these commands, on the terminal, everything goes fine but if I save the loop as script.sh and I try to run the script I obtain different errors.
Of course, I made the script executable with chmod +x and I also changed the syntax of the script using awk '{ sub("\r$", ""); print }' myscript.sh > myscript1.sh since I edited it in Windows(otherwise ubuntu fails to open it).
But when I launch the script containing the loop, it says that it is not able to open the files in the FOLDER (Failed to open BAM file /*.bam or BAD permission denied). I tried both to open it just giving the command ./myscript1.sh or also using sudo ./myscript1.sh.
What I'm missing? I have in some way link the variable I establish in the terminal to a new variable in the script saved?
thanks
Francesca
You need to export the variables so that they'll be inherited by the shell process running the script.
export FOLDER="/mnt/c/Users/franc/Desktop/nuova"
export species=mm10
export fragmentsize=200
export window=200
export gap=200
export output="/mnt/c/Users/franc/Desktop/nuova/sicer"
I have to accept or not accept the commit on a particular repository based on the comments with the commit (using hooks). I don't know how to do it. I have to do it on a Windows device. I read somewhere that I should modify the pre-commit.tmpl file to accept just that word as the commit so I did modify this statement:
SVNLOOK=/usr/local/bin/svnlook
$SVNLOOK log -t "$TXN" "$REPOS" | \
grep ""[a-zA-Z0-9]"" > /dev/null || exit 1
into this:
SVNLOOK=/usr/local/bin/svnlook
$SVNLOOK log -t "$TXN" "$REPOS" | \
grep "^.*hello.*$" > /dev/null || exit 1
Also, it says to change the .tmpl extension for windows. But I don't know if a grep search is right also, what is the other alternative to doing the same task?
The exampels inside the .tmpl files are made for unix and using unix commands. You need to install the appropriate unix tools and adapt the scripts to your architecture(modifying paths etc..)
On windows you also need to rename the file to .bat so it is executable.
Note that no environment variables are available in hook scripts.
I would recommend to use python as a platform independent way of providing hook scripts. There are tons of python hook scripts available.
I am trying to download a huge file via curl. As far as I can see it there is some bash script hooked in between to deliver the correct file (in that case a virtual machine that runs IE10):
curl -s https://raw.githubusercontent.com/xdissent/ievms/master/ievms.sh | IEVMS_VERSIONS=10 bash
Due to a wobbly internet connection the download fails constantly so I need a way to resume the download at its current position. I've tried resuming the download like so:
curl -s -C - https://raw.githubusercontent.com/xdissent/ievms/master/ievms.sh | IEVMS_VERSIONS=10 bash
However, all I get is some MD5 check failed error...am I missing something?
The curl command you're running there doesn't download the VM images. It downloads a bash script called ievms.sh and then pipes the script to bash, which executes it.
Looking at the script, it looks like the file it downloads for IE10 is here:
http://virtualization.modern.ie/vhd/IEKitV1_Final/VirtualBox/OSX/IE10_Win8.zip
I think if you download that file (you could use your browser or curl) and put it in ~/.ievms, and then run the command again, it should see that the file has already been downloaded and finish the installation.
If the partially-downloaded file is already there, then you could resume that download with this command:
curl -L "http://virtualization.modern.ie/vhd/IEKitV1_Final/VirtualBox/OSX/IE10_Win8.zip" \
-C - -o ~/.ievms/IE10_Win8.zip
(Then run the original IEVMs curl command to finish installation.)
In order to use rsync I created a BASH script. It runs fine from the Cygwin shell in WIN 7 but fails when run from the WIN 7 Task Scheduler. My Task Scheduler Script is a simple:
c:\cygwin\bin\bash.exe -l -c "~user/rsync_Windows_Backup 2>&1 >> ~user/Documents_cron.log"
The initial directory is set to C:\Cygwin\bin.
My BASH script is a typical rsync command with [options] SRC DEST and some related housekeeping.
The rsync command within the "rsync_Windows_Backup" BASH script is:
/bin/time -f "\nElapse (hh:mm:ss.ss) %E" \
rsync.exe -v -rltz --chmod=a=rw,Da+x -u "$SRC" "$DEST" >> "$LOG" \
2 >> "$LOG"
$ ./rsync_Windows_Backup - succeeds.
But the Task Scheduler Job fails carping that it cannot find the DEST Folder that the BASH script references. When I do a "cd DEST" from the BASH command line the Folder is avialable and can be written to.
I should add some more details that the sender is a WIN 7 desktop that is mapped to a Vista desktop receiver with a drive mapping J:. The BASH script does start but fails with:
rsync: writefd_unbuffered failed to write 4 bytes to socket [sender]: Broken pipe (32)
rsync: mkdir "/cygdrive/J/DocumentsBackup" failed: No such file or directory (2) rsync error: error in file IO (code 11)
I have tried several ideas to influence how WIN 7 handles mappings and permissions assuming this is the root of the problem. So far nothing seems to help.
Another characteristic is that the exact same BASH script and Task Scheduler Job does succeed it WIN Vista Business Edition. So I am assuming there is something in WIN 7 that I am missing.
I am stumped and could use some guidance.
Thanks.
I now have this working in Win 7 from the task scheduler as I need. Thank you to #netubsi and #firerat of LinuxQuestionsorg and #konsolebox for the suggestions that lead to a solution.
Here is what I did:
cmd /c net use T: '\\server\share' # Created a separate temporary share for Cygwin
DEST="/cygdrive/T/User/FolderBackup/" # Use temporary Share in Destination
rsync -avuz --copy-links "$SRC" "$DEST" # Do backup
cmd /c net use T: /delete # Remove temporary share
It appears that in WIN 7 the share created in Windows is NOT available to a Cygwin script, IF it is launced from the Win 7 task scheduler. It IS available if the script is launced from the Cygwin command line. It also appears that this is NOT an issue in Win Vista.
This seems odd to me. Perhaps there is another explanation that I am missing. However I am just relieved to have this working!!
You can also just use the network address directly in cygwin:
DEST="//server/share/User/FolderBackup"
Cygwin mounts local and mapped drives under /cygdrive. Using taskscheduler in win7 if you list the contents of /cygdrive, all you will see are local drives???
First option is to run your script as
c:\cygwin\bin\bash.exe -l -c "~/rsync_Windows_Backup >> ~/Documents_cron.log 2>&1"
If you want to capture the stderr output as well, you have to place it in front to copy the fd of the file, and not of stdout.
Make sure that rsync_Windows_Backup has executable permissions. Running ls -l ~/rsync_Windows_Backup should show it.
If it doesn't work, try to use absolute paths. On your Cygwin screen where the current direcory shows ~ in the prompt type pwd which would show something like
User#System ~
$ pwd
/home/User
Basing from that as an example your command should now be like:
c:\cygwin\bin\bash.exe -l -c "/home/User/rsync_Windows_Backup >> /home/User/Documents_cron.log 2>&1"
After designing a simple shell/bash based backup script on my Ubuntu engine and making it work, I've uploaded it to my Debian server, which outputs a number of errors while executing it.
What can I do to turn on "error handling" in my Ubuntu machine to make it easier to debug?
ssh into the server
run the script by hand with either -v or -x or both
try to duplicate the user, group, and environment of the error run in your terminal window If necessary, run the program with something like "su -c 'sh -v script' otheruser
You might also want to pipe the result of the bad command, particularly if run by cron(8), into /bin/logger, perhaps something like:
sh -v -x badscript 2>&1 | /bin/logger -t badscript
and then go look at /var/log/messages.
Bash lets you turn on debugging selectively, or completely with the set command. Here is a good reference on how to debug bash scripts.
The command set -x will turn on debugging anywhere in your script. Likewise, set +x will turn it off again. This is useful if you only want to see debug output from parts of your script.
Change your shebang line to include the trace option:
#!/bin/bash -x
You can also have Bash scan the file for errors without running it:
$ bash -n scriptname