2
голосов
3ответов
8053 просмотров

Comparing two lists with a shell script

Suppose I have two lists of numbers in files f1, f2, each number one per line. I want to see how many numbers in the first list are not in the second and vice versa. Currently I am using grep -f f2 -v f1 and then repeating this using a shell script. This is pretty slow (quadratic time hurts). Is ...

16
голосов
2ответов
16984 просмотров

How do I fetch the folder icon on Windows 7 using Shell32.SHGetFileInfo

I have the following code which works on Windows XP and Vista - both 32 and 64 bit: public static Icon GetFolderIcon(IconSize size, FolderType folderType) { // Need to add size check, although errors generated at present! uint flags = Shell32.SHGFI_ICON | Shell32.SHGFI_USEFILEATTRIBUTES;...

34
голосов
8ответов
85277 просмотров

How to run PHP exec() as root?

I'm trying to build a firewall manager in PHP, but when I execute, <?php exec('iptables -L'); ?>, the result array is empty. I have tried, <?php echo exec('whoami'); ?>, and the response is www-data (the user that Apache is using). What can I do to execute the exec function as root? ...

2
голосов
2ответов
322 просмотров

graceful degradation for globbing on terminal

Whenever glob pattern match fails, it stops the whole job. For instance, $ mv *.jpg *.png folder1 && blahblah mv: cannot stat `*.jpg': No such file or directory *.png isn't moved to folder1 and blahblah is not run. And the script below works only for the case when both .[A-z]* and * s...

3
голосов
4ответов
2473 просмотров

java shell for executing/coordinating processes?

I know about using Runtime.exec, you pass it a native program to run + arguments. If it's a regular program, you can run it directly. If it's a shell script, you have to run an external shell program like sh or csh or cmd.exe. Is there some Java class (either standard or open-source) that implem...

2
голосов
12ответов
833 просмотров

Which language to use for implementing few Linux shell commands (homework) - plain C or C++?

I need to implement a few commands of Linux shell for my homework - 5 or 6 of them, including ls. Do not know much about which parameters to implement for each of commands... I planned to use C++, but when I asked my colleague for advice what language to choose - plain C or C++, he said that int...

2
голосов
3ответов
3320 просмотров

busybox sh wrapper to add extra functionality

I need a simple busybox sh wrapper which will do: IF "-Q" PARAMETER IS PROVIDED THEN acommand ALL PARAMETERS BUT "-Q" 2>&1 1>/dev/null ELSE acommand ALL PARAMETERS FI Parameters may include spaces. BTW I want to run the script with busybox sh and it doesn't support...

51
голосов
6ответов
16183 просмотров

How to programmatically determine whether the Git checkout is a tag and if so, what is the tag name

In a Unix or GNU scripting environment (e.g. a Linux distro, Cygwin, OSX), what is the best way to determine whether the current checkout is a Git tag. If it is a tag, how can I determine the tag name? One use of this technique would be automatically labeling a release (like svnversion would do ...

284
голосов
20ответов
116913 просмотров

How to programmatically determine the current checked out Git branch

In a Unix or GNU scripting environment (e.g. a Linux distro, Cygwin, OSX), what is the best way to determine which Git branch is currently checked out in a working directory? One use of this technique would be automatically labeling a release (like svnversion would do with Subversion). Please a...

79
голосов
10ответов
64270 просмотров

Is there any simple way to benchmark python script?

Usually I use shell command time. My purpose is to test if data is small, medium, large or very large set, how much time and memory usage will be. Any tools for linux or just python to do this?

2
голосов
3ответов
56646 просмотров

Running a jar from shell script

I have a jar file named umar.jar in /root/umar/bin directory. I have a shell script file run.sh in same directory. Following is the content of run.sh #!/bin/bash "$JAVA_HOME"/bin/java -jar /root/umar/bin/umar.jar Now when I run the shell script, I get the following error Exception in thread "...

1
голосов
3ответов
1971 просмотров

Running a command in shell script

I have a shell script file (run.sh) that contains the following: #!/bin/bash %JAVA_HOME%/bin/java -jar umar.jar when i try to run it (./run.sh), it gives me following: umar/bin/run.sh: line 1: fg: no job control However if I run same command directly on shell, it works perfectly. What's wr...

24
голосов
7ответов
54043 просмотров

Iterating through a range of ints in ksh?

How can I iterate through a simple range of ints using a for loop in ksh? For example, my script currently does this... for i in 1 2 3 4 5 6 7 do #stuff done ...but I'd like to extend the range way above 7. Is there a better syntax?

11
голосов
7ответов
16709 просмотров

Shell Scripting: Using bash with xargs

I'm trying to write a bash command that will delete all files matching a specific pattern - in this case, it's all of the old vmware log files that have built up. I've tried this command: find . -name vmware-*.log | xargs rm However, when I run the command, it chokes up on all of the folders ...

0
голосов
3ответов
512 просмотров

Keep shell open with PHP to allow multiple calls?

How can I allow the shell session to stay open until I close it with PHP? In my example I want to use NcFtp to publish some files through shell command. I want to leave PHP's built in FTP because it is much much slower and performance is an issue. It is easy to use ncftpput to publish a file or...

13
голосов
9ответов
14533 просмотров

Find highest numbered filename in a directory where names start with digits

I have a directory with files that look like this: 001_something.php 002_something_else.php 004_xyz.php 005_do_good_to_others.php I ultimately want to create a new, empty PHP file whose name starts with the next number in the series. LIST=`exec ls $MY_DIR | sed 's/\([0-9]\).*//g' | tr...

42
голосов
14ответов
5667 просмотров

Why don't I see pipe operators in most high-level languages?

In Unix shell programming the pipe operator is an extremely powerful tool. With a small set of core utilities, a systems language (like C) and a scripting language (like Python) you can construct extremely compact and powerful shell scripts, that are automatically parallelized by the operating sy...

3
голосов
5ответов
2227 просмотров

Bourne shell script to convert a number to telephone format

I want to change a number such as 1234567890 to 456-7890; is there a way to do this in Unix Shell programming?

1
голосов
2ответов
404 просмотров

shell script not executed

I'm trying to set the environment variables in shell script. The command "source .bashrc" is not executed. As long as type the last line in the terminal, everything works fine. What's wrong with my script? thx. echo "export CLASSPATH=.:$HOME/java/lib export JAVA_HOME=$HOME/java export PATH=.:$PA...

1
голосов
3ответов
579 просмотров

What is the simplest way to execute arbitrary process with stdin, stdout forwarded to a socket?

I'm interested in two situations: How to do it from C++? How to do it from system's shell? Answers for Linux, Windows and OSX are welcome.

0
голосов
1ответов
166 просмотров

Complex webapp deployment script: Shell too limited?

I inherited some release scripts that prepare and deploy a PHP webapp to around 20 servers. The scripts are written in shell and I personally find them somewhat cumbersome to maintain. That may have have to do with the way they are written but I'm looking to see if anyone has opinion or experienc...

2
голосов
5ответов
6124 просмотров

How do I use tr to substitute '--' string

I have an output: -- out1 -- out2 -- out3 I want to get the output: out1 out2 out3 I thought of using: tr '--' '' but it doesn't recognize '--' to be the first string I want to substitute. How do I solve this?

1
голосов
5ответов
9463 просмотров

Best tool in unix for viewing large files

I am a novice in unix. I am facing a problem in viewing big log files in unix using vi. Could you please suggest the best tool for fast viewing of big files on unix? Additionally, could you to post your own ways of viewing the big files on unix?

0
голосов
4ответов
1932 просмотров

Running a java application through shell script in a JSP/Servlet

I am running a shell script through a web application. This shell script looks something like `#! /bin/bash user="" pass="" db_url="" db_instance="" sqlplus -s $user/[email protected]$db_url/$db_instance @ ./SqlScripts/foo.sql sqlplus -s $user/[email protected]$db_url/$db_instance @ ./SqlScripts/bar.sql CLASS_PATH=...

0
голосов
5ответов
119 просмотров

problem in shell script

I am trying this option #!/bin/ksh echo $1 awk '{FS="=";print $2}' $1 and on the command line test_sh INSTANCE=VIJAY but awk is failing. Is there any problem here? Basically I need the value VIJAY passed on the command line.

0
голосов
5ответов
139 просмотров

Problem in running a script

i have unix shell script which is need to be run like below test_sh XYZ=KLMN the content of the script is #!/bin/ksh echo $XYZ for using the value of XYZ i have do set -k before i run the script. is there a way where i can do this without doint set -k before running the script. or is t...

-1
голосов
4ответов
212 просмотров

problem in a shell command

i am trying the following command on the command line ps -u `id | cut -f2 -d"=" | cut -f1 -d"("` -f | grep ppLSN | awk '{print $9}' | awk '{FS="=";print $2}' | grep KLMN | wc -l the value of teh command is returned as 7. but when i am putting the same command inside a script abc_sh like bel...

0
голосов
2ответов
945 просмотров

run few commands simultaneously

I am writting a shell script and i want these commands to run at the same time find ./incoming/kontraktor/ -type f -name '*.html' | sort | awk 'NR % 3 == 1' | ./bin/foo.py -m 3 -b 1 | next_command >> log/foo_log.log 2>&1 find ./incoming/kontraktor/ -type f -name '*.html' | sort | aw...

133
голосов
12ответов
151355 просмотров

Get exit code of a background process

I have a command CMD called from my main bourne shell script that takes forever. I want to modify the script as follows: Run the command CMD in parallel as a background process (CMD &). In the main script, have a loop to monitor the spawned command every few seconds. The loop also echoes som...

25
голосов
4ответов
9913 просмотров

paste without temporary files in Unix

I'm trying to use the Unix command paste, which is like a column-appending form of cat, and came across a puzzle I've never known how to solve in Unix. How can you use the outputs of two different programs as the input for another program (without using temporary files)? Ideally, I'd do this (w...