Pages

June 17, 2016

Bash Scripts for Transfering Files Between Server and Local Computer


Yes, Bash scripts again! Two scripts for copying files from server to local computer and vice versa. Usually I use them if I want to work with some text files in graphical editors, not in Vim. So I can download the file to my local computer and then upload it back to the server.

./copy-file-from-server.sh [SERVER] [FILE]
./copy-file-to-server.sh [SERVER] [FILE]

Basically, it's the same as using scp command, but scripts allow you to define short names for servers. For example, instead of username@192.168.1.1, username@some.hostname.com or something1-23-45-678-9.eu-east-0.compute.amazonaws.com you can use short names, like test, demo, latest etc.

To set your own hosts in the script you need to modify function setHost(). In the copy-file-from-server.sh script you can also set a fixed directory where you want to download files. Currently it downloads to the same directory where script was run, but you can change it in the downloadFile() function.

Also, don't forget about aliases! You can set some short name to the script and use it in every directory.

June 7, 2016

Script for Sending E-mails About Certain JIRA Issues


"Still life with various Unix shells" by Bartholomeus van der Ast (source)


Recently I wrote a new Bash script, that can be useful for others.

./notify-about-issues.sh
It sends e-mail when some specific JIRA JQL query returns any result. You can create any JQL query you want: return issues that were created in specific project, return issues that were commented by some specific user, return issues where status was changed etc. Probably you want to limit the query by period to monitor only recent changes. This period can be the same as the frequency of the e-mail sending. For example, if you want to check this filter every 10 minutes, then you can check changes in last 10 minutes.

To implement this script you need to define following variables in the code:
$jiraUrl – URL of your JIRA
$filter – JQL query, encoded for URL (you can use some online URL encouder/decoder)
$user – JIRA username
$password – JIRA password (authentication is very primitive and not safe, but you can use some general credentials or keep the script file in safe place)
$to – e-mail where notification should be sent
$from – e-mail from whom notification should be sent (could be the same as to)
$subject – subject of the e-mail

Automatic running can be configured with crontab – read post 10 Mac OS X Terminal Commands for Testers for details.

The most complex part is to write a propper JQL query that returns exactly what you want. You can use Advanced searching documentation for complex queries or ask an advice in Atlassian Answers.