shell-scripting

Can PowerShell (or script) on Windows / Mac / Ubuntu list file / directory structure easily?

Can PowerShell on Windows by itself or using simple shell script, list files and directory this way: (or using Mac OS X or Ubuntu's shell script) audio mp3 song1.mp3 some other song.mp3 audio books 7 habits.mp3 video samples up.mov cars.mov Unix's ls -R or ls -lR can't seem to list it in a tree structure unf...

Unix - File Creation Date

For an assignment I need to determine the creation time of a random file. As far as I know, Unix does not store the creation time (in contrast to *-BSD). I think I've read somewhere that you should ask for the modification time instead but I don't know where and asking Google doesn't give me a non-ambigious answser either. Any ideas? ...

Convert 1000 to 1024 bytes

Im trying to convert a size, lets say 244410368 bytes to xxxxxx mebibyte (MiB) but I have no idea how. All this 1000 and 1024 bytes/bits are rather confusing. ...

How do I remove newlines from a text file?

Hey there everyone ... I have the following data, and I need to put it all into one line... I have this: 22791 ; 14336 ; 22821 ; 34653 ; 21491 ; 25522 ; 33238 ; I need this: 22791;14336;22821;34653;21491;25522;33238; If anyone could help me it would be a great !! Thanks in advance! --------- EDIT No of these commands...

What's the easiest in a shell script to ensure its not run as root?

I have a Java application executed from a ([ba]sh) shell script and unfortunately sometimes the people responsible for deploying it and starting it fail to switch to the appropriate user before starting the application. In this situation I'd like the application to not run at the very least, and ideally issue a warning not to do that. ...

How to take out some of the new lines of a document

Hey there!! Firstly, I'm really new on this and I'm having difficulties... I have this data: [05/Apr/2010:09:59:34 -0300] /~bcc/topo-zero.html 200 238 2 [05/Apr/2010:10:01:19 -0300] /~bsi/materiais/ed/u6.html 200 286960 3 [05/Apr/2010:10:04:56 -0300] /~firedo/AISG/AISGroupContributions.html 200 33193 2 ...

How can I run a program in the background (non blocking) with php?

Hi, I want to run a shell script in php, but this shell script takes a long time to execute (it has sleep in it), I don't want the web server to block when executing this script. I tried exec() and shell_exec() in php but the server stops until the shell script finishes! I thought of doing fork in the shell script itself but I don't kn...

Return a single value from a shell script function

Example: #!/bin/sh a() { R=f ls -1 a* [ "$?" == "1" ] && { R=t; } echo $R } r=`a` echo $r $r contains "t" or "f" but also the output of the "ls" command. I may write ls -1 a* >/dev/null 2>/dev/null, but if there is a more complex script that can be lead to errors. Is there any way to return a single value from a() ? ...

Shell script uses arguments from first run when run a second time

Hi all, I am operating in a Korn Shell, and attempting to run a simple chdb script I wrote. If run with no arguments, it prompts the user with a list of databases and waits for a selection. If called with a single numeric argument, it will automatically make the selection for the user. Example: > . chdb Select the database sid from ...

Powershell help, if process exists, stop it, else start a service??

Hi All, I'm pretty new to Powershell. I have 2 different scripts I'm running that I would like to combine into one script. Script 1 has 1 line Stop-Process -ProcessName alcore.* -force It's purpose is to end any process that begines with "alcore." Script 2 has 1 line as well Start-Service -displayname crk* It starts any service ...

Shell script through php web page

Hi, I want to run a shell script which contains ssh command to run through a php web page. The shell script executes, but skips all the ssh commands. Is there a way to do this. Thanks ...

How to get expect -c to work in single line rather than script

Hi I was wondering if anyone had any examples of how to use expect with -c. Running: my_machine~/opt/ams/data/ep/success$ expect -c "spawn /usr/bin/scp xmlEventLog_2010-03-22T14-28-36_PFS_1_2.xml [email protected]:/opt/ams/epf_3_4/xmlEventLog_2010-03-22T14-28-36_PFS_1277900174_2.xml; expect { '*password:*' { send 'ad'\r\n }}" Doe...

I need to make a large directory with several sub-directories portable

I have a dataset contained in a directory that has about 30,000 sub-directories. Each of these directories contains a text file and another sub-directory. This sub-directory contains some number of text files (ranging from 0 text files, to hundreds). Many of my colleagues use this dataset, but as it is it takes at least 6 hours to tra...

how to create AppleScript app to run a set of terminal commands

How would I go about creating an AppleScript command that when I just run the script (or double click it in Finder?), it would run a set of terminal commands? The set of commands completely remove MySQL, and it has become a pain to constantly write them out. The commands are: sudo rm /usr/local/mysql sudo rm -rf /usr/local/mysql* sudo r...

Loop over the arguments array, without knowing how many arguments, in a shell script?

Hi, I want to pass many arguments to a shell script which I don't know how many arguments they are going to be and I want to handle them. I did the following code: int=$1 src=$2 r=$3 string=$4 duration=$5 ./start.sh $int $r $src "$string" sleep $duration shift; shift; shift; shift; shift while [ $# -gt 2 ] do r=$1 string=$2 ...

remove all but last 5 directories with shell script and find command

-not sure if this belongs here or on serverfault- What I want to do it list all directories in a directory and delete all of them, except for the last 5. We have a deployment system in place that will incrementally do something link this: /var/www/html/build1 /var/www/html/build2 /var/www/html/build3 /var/www/html/build4 /var/www/html/...

Shell script: Get name of last file in a folder by alphabetical order

I have a folder with backups from a MySQL database that are created automatically. Their name consists of the date the backup was made, like so: 2010-06-12_19-45-05.mysql.gz 2010-06-14_19-45-05.mysql.gz 2010-06-18_19-45-05.mysql.gz 2010-07-01_19-45-05.mysql.gz What is a way to get the filename of the last file in the list, i.e. ...

PHP system() help no simple commands work

I am trying to run a shell from one of my controllers in a PHP codeigniter applications, I am trying to run the file /x/sh/xpay4.sh however I just get 127 returned to the screen, I can even use basic commands like ls or pwd can any suggest why this would be, I thought it might be safe_mode when I ini_get('safe_mode') it returns 1 ...

How to make terminal not print " ^Killed by signal 2. " on catching a SIGINT

I am traping a signal SIGINT in one of my script I am writting for my project. trap sigint_handler SIGINT I am having signal handler sigint_handler() { # echo caught signal, now quiting.... exit $? } So now when the script gets a CTRL+C signal it gets it and exits. And on terminal it prints this message: $^Killed by sig...

how to pre-construct awk statement to pass to awk on command line?

I have a shell script that constructs an awk program as a string then pass that string to awk. This is because I want to use values of shell variables in the awk program. My code looks like this: awk_prog="'{if (\$4~/$shell_var/) print \$1,\$2}'" echo $awk_prog awk $awk_prog $FILENAME However, when I pass the string to awk, I always...