shell-scripting

Make windows batch file not close upon program exit

It's all in the title. When the program is over, I want it to say "Press any key to continue..." so I can scroll thru the output. ...

How to remove all .svn directories from my app directories.

One of the mission of an export tool I have in my application, is to clean all .svn directories from my app directory tree. I am looking for a recursive command in linux shell that will traverse the entire tree and delete the .svn files. I am not using export, as this script will be used for some other file/directory names which are not ...

How set the From email address for mailx command?

I'm working on a korn shell script running on a Solaris server that will send out an email when and error condition is met. I'm sending the email via mailx. Question: How to I set the "From" email address on the mailx command? Current Code: echo ${msg_txt} | mailx -s "Script Failure" ${to_email} Note: The command works fine, ho...

Iterating over options and quoted/unquoted arguments passed to bash script

I have a bash script that uses getopt to parse its parameters. It correctly handles switches and long options, as well as arguments and quoted arguments, but I cannot figure out how to iterate over the options/arguments string returned by the backticks. Something like: params=`getopt -o ab -l ccc -- "$@"` echo $params for param in "$pa...

Check if a package is installed and then install it if it's not.

I'm working on a Ubuntu system and Currently this is what I'm doing: if ! which command > /dev/null; then echo -e "Command not found! Install? (y/n) \c" read if "$REPLY" = "y"; then sudo apt-get install command fi fi Is this what most people would do? Or is there a more elegant solution? ...

Read Makefile variable from console if not set

I'm updating a Makefile that accesses some resources from an external source, i.e. there is a rule of the form $(External)/% : cvs up $@ ...which works as expected for unrestricted resources. Now, there has been a feature drift, and the external resources requires a more complex login, so the rule has changed to something not too...

error executing shell script in PHP

I am trying to execute a shell command via: <php echo shell_execute("tac /home/kusmuk/access-logs/kusmuk.org"); ?> But it does not give any output. What could be the reason? Although it does not work, the following lines work as expected: <php echo shell_execute("ls -al triogrup.com"); ?> //outputs: -rw-r----- 2 root kusmuk 28640 Au...

History of commands with user

Can i know who all the users have executed which command on a machine? ...

How to do something to every file in a directory using bash?

I started with this: command * But it doesn't work when the directory is empty; the * wildcard becomes a literal "*" character. So I switched to this: for i in *; do ... done which works, but again, not if the directory is empty. I resorted to using ls: for i in `ls -A` but of course, then file names with spaces in them get s...

How to test filename expansion result in bash?

I want to check whether a directory has files or not in bash. My code is here. for d in {,/usr/local}/etc/bash_completion.d ~/.bash/completion.d do [ -d "$d" ] && [ -n "${d}/*" ] && for f in $d/*; do ...

Should I make Linux Shell Script or Java program?

I need to generate multiple databases to SQL, so I need script/program to automatically generate those to SQL and generate files to jboss server. Our client server is running in Linux, but I develop on Windows machine. Should I make script with as Linux script or write Java program that could make same things? ...

Encrypt resources in Cocoa app?

Hi, I have a shell script stored in the resources folder of my Cocoa app. If used improperly it could be dangerous (even though I have taken precautions to reduce exploits, such as using the absolute path to commands) so is there any way to encrypt the script in binary format, then decrypt it when it needs to be used? Thanks ...

Reading live output from shell script and updating progress bar

Hi, I have a shell script logging a list of numbers (1, 2, and so forth, one per line) to a log file. I need my ObjC app to read the log file every X seconds and then update my progress bar accordingly based on the last number logged in the log file. What's the best way to do this? ...

MySQL from the command line - can I practically use LOCKs?

I'm doing a bash script that interacts with a MySQL datatabase using the mysql command line programme. I want to use table locks in my SQL. Can I do this? mysql -e "LOCK TABLES mytable" # do some bash stuff mysql -u "UNLOCK TABLES" The reason I ask, is because table locks are only kept for the session, so wouldn't the lock be released...

shell problem: sending variable with multiple flags to a cmd

Hello Shell Experts, In the following, the echo output is right, but the pgm is not receiving the flags correctly. Appreciate any insights. script file: flags="-umc -v -v " r="";for d in `ls -d /tmp/passenger*`; do r="$r -x $d"; done flags="$flags $r" echo $flags /usr/sbin/tmpwatch "$flags" -x /tmp/.X11-unix -x /tmp/.XIM-unix \ -x...

Shell Script that goes up N folders in the file system

Hey there, I just found this very usefull shell script here on SO but unfortunately it's not working on Mac OS X 10.5. This is the script in question(copied it for convenience): #!/bin/bash LIMIT=$1 P=$PWD for ((i=1; i <= LIMIT; i++)) do P=$P/.. done cd $P I tried to echo $P at the very end and it's returning the right path, but...

Is there an easy way to calculate quantiles with bash?

Lets say I have a log file from a web server with response times per request: _1st_request 1334 _2nd_request 345 _3rd_request 244 _4th_request 648 ......... etc Is there an easy way with bash scripting to find the top decile (10-quantile)? In other words to answer the question: How slow was the slowest request if I exclude the slowest...

Kill process after launching with AuthorizationExecuteWithPrivileges

If I launched a shell script using AuthorizationExecuteWithPrivileges what would be the easiest way to kill the script and any other processes that it spawned. Thanks ...

Login to a Linux server from a Windows system using batch files

Hello All , i want to make one script which will automatic telnet the system . I have to access from my system(Windows Xp) to my server(Linux) spawn telnet <machine ip> expect "login:" send "<username>\n" expect "Password:" send "<password>\n" Is the above script is correct? 1) If yes means, how can i access this script from my ...

Get MySQL Cell in shell script

I would like to execute a MySQL command in a shell script/cron job that returns a dynamic number of rows in which I can access a specific field from those rows. I would then like to loop through this performing additional commands on those field entries. My two questions then are: How do I return a set of rows (ideally just a single ...