Friday, 7 February 2014

Some batch file commands

Funny but I've tried to change directory in a command prompt by simply typing:

CD D:\
and sure enough this does not work.
To change to new directory add /D  (case insensitive)
 
cd /d  d:\
 or just
D:

Some reserved variables:

%~dp0  -> this will contain the path to the script
%0      -> this will hold the path+the name of the script

%1 up to %9   -> this in the script will pick up arguments that may have been passed to the script when it was launched from command line


Wednesday, 15 January 2014

df and du

'du' - Finding the size of a directory

$ du
Typing the above at the prompt gives you a list of directories that exist in the current directory along with their sizes. The last line of the output gives you the total size of the current directory including its subdirectories. The size given includes the sizes of the files and the directories that exist in the current directory as well as all of its subdirectories. Note that by default the sizes given are in kilobytes. 



$ du / -h --max-depth 1 list the same info in GB/MB for the root directory and go only one level in depth/down

$ du /home/deyan
The above command would give you the directory size of the directory /home/deyan


$ du -h
This command gives you a better output than the default one. The option '-h' stands for human readable format. So the sizes of the files / directories are this time suffixed with a 'k' if its kilobytes and 'M' if its Megabytes and 'G' if its Gigabytes.


$ du -ah

This command would display in its output, not only the directories but also all the files that are present in the current directory. Note that 'du' always counts all files and directories while giving the final size in the last line. But the '-a' displays the filenames along with the directory names in the output. '-h' is once again human readable format.


$ du -c
This gives you a grand total as the last line of the output. So if your directory occupies 30MB the last 2 lines of the output would be

30M .
30M total

The first line would be the default last line of the 'du' output indicating the total size of the directory and another line displaying the same size, followed by the string 'total'. This is helpful in case you this command along with the grep command to only display the final total size of a directory as shown below.


$ du -ch | grep total
This would have only one line in its output that displays the total size of the current directory including all the subdirectories.


$ du -s
This displays a summary of the directory size. It is the simplest way to know the total size of the current directory.


$ du -S
This would display the size of the current directory excluding the size of the subdirectories that exist within that directory. So it basically shows you the total size of all the files that exist in the current directory.

-

'df' - finding the disk free space / disk usage

$ df
Typing the above, outputs a table consisting of 6 columns. All the columns are very easy to understand. Remember that the 'Size', 'Used' and 'Avail' columns use kilobytes as the unit. The 'Use%' column shows the usage as a percentage which is also very useful.


$ df -h
Displays the same output as the previous command but the '-h' indicates human readable format. Hence instead of kilobytes as the unit the output would have 'M' for Megabytes and 'G' for Gigabytes.


Monday, 6 January 2014

Remove a symbolik link in Linux

Symbolik link is one that points to a file or directory, a kind of shortcut.
When it needs to be removed and you use the auto fill in of commands in the shell (TAB key) and you type rm then the name of the link, it will automatically add the name of the link and add a slash. This slash must be deleted in the command in order to be able to delete the symlink.

# correct way 
rm mySymLink
# incorrectly added slash
rm mySymLink/
 
The first one means you delete a file (which actually is the symlink) while the second is you want to delete a directory.
That's why you will get error you try to delete directory.
Also file permissions might be needed to be set up. 

Thursday, 7 November 2013

Running two separate skype profiles

If you want to run on two independent skype instances one a single machine, for example one for your personal skype account, and one for your work account, it's very simple.

Create a shortcut to your skype.exe.
Right-click it, select "Shortcut" tab.
Add /secondary to the Target field, if you have installed Skype on the default location, then this would look something like:
"C:\Program Files (x86)\Skype\Phone\Skype.exe" /secondary
Click OK to save changes and your are done.

Enjoy your alternative second skype.

Wednesday, 6 November 2013

ERROR 267 (0x0000010B) Scanning Source Directory DIRNAME The directory name is invalid. Jenkins

A job that I run on my Jenkins CI suddenly started having this error:

ERROR 267 (0x0000010B) Scanning Source Directory DIRECTORY-PATH The directory name is invalid.


The job was using a robocopy command to find and copy all config.xml files from the JENKINS_HOME/jobs and commit them to the SVN repository for backup.
This job which was causing the issue was a matrix type of job, that was previously running on multiple slave nodes and later was changed to run to a different node, so there were left old folders in the directory:

JENKINS_HOME\jobs\JOBNAME\configurations\axis-label\NODENAME\...

So now I had these folders in that location:
\Old_NODENAME
\Current_NODENAME


What I did was to delete the \Old_NODENAME, as it obviously was not done automatically by Jenkins once I had changed the matrix configuration (the nodes I want the job to run simultaneously)

Then I run the job again, to just make sure it was passing successfully.

I also manually deleted the info about the Old_NODENAME which was stored at the SVN.
After performing these two steps, I run the failing job again, and the error 267 was fixed.

Old and irrelevant content in the job's workspace on JENKINS_HOME/jobs and on the SVN where the job commits, were causing ERROR 267 (0x0000010B) Scanning Source Directory DIRECTORY-PATH The directory name is invalid.

OR

Another reason this error to happen was that the invalid name contained "lastSuccessful". That particular job did not have a link "Last successful artifacts" which usually is present on all jobs and is a link to the last successful build artifacts of that job. In one case such a link was missing for whatever reason, and I had to recreate the job and run it in order to make this link appear in the UI of the job in Jenkins.
 

Friday, 16 August 2013

Error 0x8007046A:Not enough server storage is available to process this command.

I was trying to move a 10 GB folder on another network location but this error prevents me from doing it:
 Error 0x8007046A:Not enough server storage is available to process this command.


1. Click Start | Run and type regedit.
2. Locate the registry key HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\LanmanServer\Parameters
3. Click Edit and Add Value with the following parameters

Name: MinFreeConnections

Data Type: Reg_DWORD

Decimal: 5

This fixed my problem.

Tuesday, 26 March 2013

Directory-based selection in ANT

To match a pattern of path to resources, use *:

*   matches only the first sub-directory and its content, plus the files of the current dir, no other directories
**  matches all sub-directoryes and their content
   for example, c:\path\to\something\**    will match everything under \something

to include the current dir for file search, start pattern path with **


Matching is done per-directory. This means that first the first directory in the pattern is matched against the first directory in the path to match. Then the second directory is matched, and so on. For example, when we have the pattern /?abc/*/*.java and the path /xabc/foobar/test.java, the first ?abc is matched with xabc, then * is matched with foobar, and finally *.java is matched with test.java. They all match, so the path matches the pattern.
To make things a bit more flexible, we add one extra feature, which makes it possible to match multiple directory levels. This can be used to match a complete directory tree, or a file anywhere in the directory tree. To do this, ** must be used as the name of a directory. When ** is used as the name of a directory in the pattern, it matches zero or more directories. For example: /test/** matches all files/directories under /test/, such as /test/x.java, or /test/foo/bar/xyz.html, but not /xyz.xml.
There is one "shorthand": if a pattern ends with / or \, then ** is appended. For example, mypackage/test/ is interpreted as if it were mypackage/test/**.
Example patterns:
**/CVS/* Matches all files in CVS directories that can be located anywhere in the directory tree.
Matches:
      CVS/Repository
      org/apache/CVS/Entries
      org/apache/jakarta/tools/ant/CVS/Entries
      
But not:
      org/apache/CVS/foo/bar/Entries (foo/bar/
      part does not match)
      
org/apache/jakarta/** Matches all files in the org/apache/jakarta directory tree.
Matches:
      org/apache/jakarta/tools/ant/docs/index.html
      org/apache/jakarta/test.xml
      
But not:
      org/apache/xyz.java
      
(jakarta/ part is missing).
org/apache/**/CVS/* Matches all files in CVS directories that are located anywhere in the directory tree under org/apache.
Matches:
      org/apache/CVS/Entries
      org/apache/jakarta/tools/ant/CVS/Entries
      
But not:
      org/apache/CVS/foo/bar/Entries
      
(foo/bar/ part does not match)
**/test/** Matches all files that have a test element in their path, including test as a filename.