scripting

Windows/Dos scripting FOR command to rename all files in a directory

I am trying to rename all the files present in a windows directory using FOR command as follows at the dos prompt: for %1 in (.) do ren %1 test%1 E.g. This renames a file enc1.ctl to testenc1.ctl enc2.ctl to testenc2.ctl Thats not what i want. What i want is enc1.ctl renamed to test1.ctl enc2.ctl renamed to test2.ctl How do i ...

How do I parse command line arguments in bash?

Say I have a script that gets called with this line: ./myscript -vfd ./foo/bar/someFile -o /fizz/someOtherFile or this one: ./myscript -v -f -d -o /fizz/someOtherFile ./foo/bar/someFile What's the accepted way of parsing this such that in each case (or some combination of the two) $v $f $d will all be set to true and $outFile will ...

In the bash script how do I know the script file name?

How can I determine the name of the bash script file inside the script itself? Like if my script is in file runme.sh, than how would I make it to display "You are running runme.sh" message without hardcodding that? Thanks, ...

How to update contacts in Zimbra by scripting ?

I have a Zimbra installation and I need to programmaticaly update contacts in it. It seems that its REST interface is only working to add new contacts, but I need to update existing ones. Is there a way, tool or something, open-source, to do that ? ...

what would be the impediments to creating an "Europanto" type universal scripting language?

After switching back and forth between several scripting languages this week, I found myself thinking how similar they all are. Yet I'm always reaching for Google (or nowadays SO) to remember details like what the local equivalents of "instanceof" and "endswith" are, or the right syntax to declare an interface, or whatever. This remind...

How can I search through stackoverflow questions from a script?

Given a string of keywords, such as "python best practices", I would like to obtain the first 10 stackoverflow questions that contain that keywords, sorted by relevance (?), say from a python script. My goal is to end up with a list of tuples (title, URL). How can I accomplish this? Would you consider querying google instead? (How would...

Fastest "Get Duplicates" SQL script

What is an example of a fast SQL to get duplicates in datasets with hundreds of thousands of records. I typically use something like: select afield1, afield2 from afile a where 1 < (select count(afield1) from afile b where a.afield1 = b.afield1); But this is quite slow. ...

Library of Useful (Difficult) SQL scripts

Does anyone know here I can find a library of common but difficult (out of the ordinary) SQL script examples. I am talking about those examples you cannot find in the documentation but do need very often to accomplish tasks such as finding duplicates etc. It would be a big time saver to have something like that handy. EDIT: Thanks ever...

Executing multiple commands from a Windows cmd script

I'm trying to write a Windows cmd script to perform several tasks in series. However, it always stops after the first command in the script. The command it stops after is a maven build (not sure if that's relevant). How do I make it carry on and run each task in turn please? Installing any software or configuring the registry etc is c...

Is it worth learning BASH when I know Perl?

All my scripting is done in Perl, I can execute one liners at the command line, and Perl regex seems way easier. Is there anything I can do in BASH that I can't do in Perl? I just don't feel like a true hacker unless I spend the time to delve in BASH and start using Sed and Awk as well. Is it worth it, or am I just asking for pain and...

Programming timing shellscript measuring program execution time at 0 seconds.

My professor wrote this shell script to time my program, and display the results. For some reason it just outputs 0s with my program. He provided the following files: timeit.csh sequence ecoli2500.txt ecoli3000.txt ecoli5000.txt ecoli7000.txt ecoli8000.txt ecoli9000.txt ecoli10000.txt Here are the contents of ...

run oracle sql script from java

i have a bunch of sql scripts that should upgrade the database when the java web application starts up. i tried using the ibatis scriptrunner, but it fails gloriously when defining triggers, where the ";" character does not mark an end of statement. now i have written my own version of a script runner, which basically does the job, but...

Is there a simple script to convert C++ enum to string?

Suppose we have some named enums: enum MyEnum { FOO, BAR = 0x50 }; What I googled for is a script (any language) that scans all the headers in my project and generates a header with one function per enum. char* enum_to_string(MyEnum t); And a implementation with something like this: char* enum_to_string(MyEnum t){ ...

How do I make the business case for Python?

How would I make a compelling argument for introducing Python into a windows environment? VBscript or Batch scripts will run on any machine and handle most administrative tasks and Java and .Net are available to handle more complex problems. I understand Python brings a lot to the table, but what specifically could it do that we can't do...

Does Windows Powershell have a Try/Catch or other error handling mechanism?

In a script, when a command-let or other executable statement errors out, is there a try/catch type of mechanism to recover from these errors? I haven't run across one in the documentation. ...

How do I reuse a command in bash with different parameters?

I have two scripts that often need to be run with the same parameter: $ populate.ksh 9241 && check.ksh 9241 When I need to change the parameter (9241 in this example), I can go back and edit the line in history. But since I need to change the number in two places, I sometimes make a typo. I'd like to be able to change the parameter ...

Why does a deleted file reappear in Vista?

I have an automated test running on my program that generates some large MPG files along with other files. After running the test, I have the script clean up after itself. The other files (a mix of binary and text files) are removed with no problems. The MPG files, however, don't get deleted. If I try and manually delete the MPG file...

Calling batch/script files from VC6/VC2005/VC2008 project files.

Is there a way to invoke an external script or batch file from VC6 (and later) project files? I have a background process that I need to kill before attempting to build certain projects (DLLS, executables) and haven't found a way to successfully do so from the project itself. I'd like simply to call a batch file with a taskkill command...

Hidden features of Bash

Shell scripts are often used as glue, for automation and simple one-off tasks. What are some of your favorite "hidden" features of the Bash shell/scripting language? One feature per answer Give an example and short description of the feature, not just a link to documentation Label the feature using bold title as the first line See al...

Script to associate an extension to a program

My customer is replacing MS Office with OpenOffice in some workstations. My program export a file to Excel using the .xml extension (using open format) and opens it using the current associated program (using ShellExecute) The problem is that OpenOffice does not register the .xml extension associated with it. Manually association works...