unix

symlink-copying a directory hierarchy

What's the simplest way on Linux to "copy" a directory hierarchy so that a new hierarchy of directories are created while all "files" are just symlinks pointing back to the actual files on the source hierarchy? 'cp -s' does not work recursively. Thanks! -Max ...

using ensript to print project dir

Hi, I've installed enscript on my mac. But don't get it to print the complete project directory (with subdirectories). Which command would I use to print all *.as and *.mxml files including subdirs? thx daniel ...

Where\How to store distributed configuration data

A single installation of our product stores it's configuration in a set of database tables. None of the installations 'know' about any other installation. It's always been common for customers to install multiple copies of our product in different datacentres, which are geographically far apart. This means that the configuration infor...

To copy files each minute at /var/www without sudo

How can you copy a folder to /var/www without sudo? My folder codes has the following permissions at /var/www 4 drwxr-xr-x 8 root root 4096 2009-08-09 03:01 codes I can only sudo cp -r ~/Dropbox/codes/ /var/www to copy the files. I cannot copy them without sudo. ...

Is it possible to make 'exec' use '$SHELL -c' instead of '/bin/sh -c' in Perl?

In Perl, is it possible to make 'exec', 'system', and 'qx' use a shell other than /bin/sh (without using a construct like 'exec "$SHELL -c ..."', and without recompiling perl)? EDIT: The motivation for this question is a bash script that does 'export -f foo' and then uses perl in a subshell to invoke the function directly via 'system "...

Apply sed to crontab lines ?

I want to programatically change the hour which certain cron jobs execute. I'm not sure whether I'm going about this the right way, but here's the plan. Jobs which are subject to change will have a comment on the end of the line "#change-enabled". 15 5 7,14,21,28 * * /path/to/executable1 #change-enabled 15 * * * * /path/to/executable2 ...

About fork system call and global variables

I have this program in C++ that forks two new processes: #include <pthread.h> #include <iostream> #include <unistd.h> #include <sys/types.h> #include <sys/wait.h> #include <cstdlib> using namespace std; int shared; void func(){ extern int shared; for (int i=0; i<10;i++) shared++; cout<<"Process "<<getpid()<<", shared " ...

Problems with variable in Unix Shell script

Hey all. I have trouble passing a variable from inside a loop. Code: # find all output.txt that has been modified last 24h ... PROCESSED=1 find ${PROCESSED_DIR} -mtime -1 -name "output.txt" | while read i do # .. and compare those with TMP_TXT if diff $i ${TMP_TXT} > /dev/null then # If both are same EXIT search...

Can I get a percentage of by how much one file differs from another?

Hi, I'm diffing a bunch of binary files, recursively. Basically, I'm running: diff --recursive --brief dir_a dir_b And this tells me which files differ, and which are only present in one of the locations. I'd like to get a bit more information, roughly, how much different they are from one another. A percentage would do. Is there ...

Bash timestamp comparisions

Im completely new to Bash scripting but I've been told, with little help, to create a file that compresses textures into PVR format only if the file has been modified since the last time the script was run. Heres the code I have so far: # variables TEXTURE_TOOL=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/texturetool INPUT...

sed: Prepend every line with the hold space.

I'm trying to convert a large number of files from a plain text layout to CSV. The first few lines of one of the files looks like this: SLICE AT X= -0.25 ELEM NO XI-COORD INWARD-NORMAL 1 0 0.000 0.000 0.000 0.000 0.000 0.000 2 0 0.000 0.000 0.000 0.000 0.000 0.000 3 ...

What's the difference between --general-numeric-sort and --numeric-sort options in gnu sort

sort provides two kinda of numeric sorts. This is from the man page on OS X: -g, --general-numeric-sort compare according to general numerical value -n, --numeric-sort compare according to string numerical value What's the difference? ...

Checking whether a command produced output

Hello all, I am using the following call for executing the 'aspell' command on some strings in Python: r,w,e = popen2.popen3("echo " +str(m[i]) + " | aspell -l") I want to test the success of the function looking at the stdout File Object r. If there is no output the command is successful. What is the best way to test that in Python?...

grab frequent username from 'last' command in unix - with exceptions

If I run this on OS X: last -10 | awk '{print $1}' I get: chop chop chop chrihopk reboot shutdown chop chop chop chrihopk How do I use sed or awk to obtain the most frequent user 'chop'? ADDITIONAL EDIT TO QUESTION: Our local admin account interferes with the results (username: support) and often we have a new starter on a clie...

Shell script problem

Hi, In my shell script i have the following line: export PATH=$PATH:/home/$USER/somedir. Say im logged in as user mike . I need to execute the shell script as root, so i run it as sudo filename.sh, so $USER becomes root in my path in that case . I want it to be that of the user running the script, i.e. mike instead of root. Is there...

How to test things in crontab

Hi, This keeps happening to me all the time: 1) I write a script(ruby, shell, etc). 2) run it, it works. 3) put it in crontab so it runs in a few minutes so I know it runs from there. 4) It doesnt, no error trace, back to step 2 or 3 a 1000 times. When I ruby script fails in crontab, I can't really know why it fails cause when I pipe o...

need same logic in windows as been done by SED below

sed 's/^#//g' < kam_account_calls.txt > kam_account_calls1.txt This command removes # from the start of the line. Please let me know how to adopt the same functionality in the Windows command shell. ...

How to grab an arbitrary chunk from a file on unix/linux

I'm trying to copy a chunk from one binary file into a new file. I have the byte offset and length of the chunk I want to grab. I have tried using the dd utility, but this seems to read and discard the data up to the offset, rather than just seeking (I guess because dd is for copying/converting blocks of data). This makes it quite slow ...

Why does Perl's glob return undef for every other call?

I'm not necessarily looking for a better way to do this, rather an explanations of the output would greatly be appreciated. Recently, a senior programmer asked me why his code worked but only for one instance. What I came to find out was that it worked every other occurrence. Here is my example: #!/usr/bin/perl -w use strict; my @li...

Non-blocking stdio

I'm working on a program which will be taking in user input from the console as well as printfing out in a separate thread. I want to avoid situations where the user is halfway through typing something in and a printf comes along and prints itself at the cursor. Is there a way to do non-blocking io in c from the console window? Ideally,...