unix

Detecting interactive shell within ksh ENV script

What's the preferred way to determine if a given ksh invocation is running an interactive shell? I have some commands in an ENV file that I would like to skip for non-interactive ksh invocations (e.g. when executing a shell script). I've seen suggesting ranging from: if [[ $- = *i* ]]; then # do interactive stuff fi ...to not ev...

Sort using only some columns

I have a 600MB tab delimited file that needs to be sorted using only the first two columns. Any lines already in order by those columns should remain in the existing order. My efforts using sort and --key seem to keep sorting the lines by the other columns. This is an example of the unsorted file: 1244072768 7234 Z 1244072768 7234 e...

Color output from shell command in Ruby

Here's a simple Ruby script: puts `ls -laG` In OS X's ls, -G is for color. When run under bash, I get color output. When the above is run from a Ruby script, I don't see color or the ANSI escape sequences in the resulting output. From what I've read, my guess is it's because the script isn't running as a tty. Is there some way to ru...

cron job seems to be timing out

Have the following cronjob set up in root's crontab: (centos 5.x) 2 * * * * /usr/bin/curl --basic --user 'user:pass' http://localhost/cron/do_some_action > /var/www/app/cronlog.log Invoking the actual command works as expected, however when the cronjob runs, it always times out. I've used set_time_limit() and related php.ini settings ...

Comparing files on the unix command line..

Suppose I have two files, A and B, and that lengthOf(A) < lengthOf(B). Is there a unix utility to tell if file B duplicates file A for the first lengthOf(A) bytes? If I do "diff A B", the output will be all the 'extra stuff' in the B file, which misses the point; I don't care what else might be in file B. If I do "comm A B", then I hav...

Reading a Unicode file in C and passing contents as ASCII via sockets

Hey, I've being trying to figure this out, but nothing seems to work. We have an application that reads thousands of transactions files using the normal "fopen fgets etc", which we parse using normal C functions "strstr, strchr, etc" and return back a normalized char *. However, now we need to read some files that are in Unicode (from ...

What's the difference between nohup and a daemon?

I was just wondering what the implication is for running a script as a daemon versus using nohup? I know what the difference is terms of forking processes etc, but what impact does that have on my script? ...

Any graphics library for unix that can draw histograms?

A python program needs to draw histograms. It's ok to use 3rd party library (free). What is the best way to do that? ...

Why are *nix commands referred to as Man(1), Diff(1), Cat(1), etc...

Possible Duplicate: Why do programs in Unix-like environments have numbers after their name? What does the (1) mean? ...

Get a Unix script to run at exactly the same time every time

I am writing a script to capture disk usage on a system (yes, I know there is software that can do this). For database reporting purposes, I want the interval between data points to be as equal as possible. For example, if I am polling disk usage every 10 minutes, I want every data point to be YYYY-MM-DD HH:[0-5]0:00. If I'm am pollin...

Easiest way to authenticate users in Linux/Unix w/o root permissions

Hi All, I'm writing a cross-platform TCP/IP server and I need to authenticate users before servicing them. Requirements stipulate that I use "native" authentication of the platform and not create my own authentication mechanism. For Linux/Unix OS family I use getpwnam to authenticate users and the most reliable way I know to make sure ...

Determining age of a file in shell script.

G'day, I need to see if a specific file is more than 58 minutes old from a sh shell script. I'm talking straight vanilla Solaris shell with some POSIX extensions it seems. I've thought of doing a touch -t YYYYMMDDHHmm.SS /var/tmp/toto where the timestamp is 58 minutes ago and then doing a find ./logs_dir \! -newer /var/tmp/toto -pr...

What is a unix command for deleting the first N characters of a line?

For example, I might want to: tail -f logfile | grep org.springframework | <command to remove first N characters> I was thinking that 'tr' might have the ability to do this but I'm not sure. Thanks in advance stackoverflow geniuses! -- LES ...

How can I measure my (SAMP) server's bandwidth usage?

I'm running a Solaris server to serve PHP through Apache. What tools can I use to measure the bandwidth my server is currently using? I use Google analytics to measure traffic, but as far as I know, it ignores file size. I have a rough idea of the average size of the pages I serve, and can do a back-of-the-envelope calculation of my band...

Is there a way to use htdigest from Windows?

I do not have ssh access to a machine with htdigest and I use Windows. Can someone help me? ...

Can you grep a file using a regular expression and only output the matching part of a line?

I have a log file which contains a number of error lines, such as: Failed to add [email protected] to database I can filter these lines with a single grep call: grep -E 'Failed to add (.*) to database' This works fine, but what I'd really like to do is have grep (or another Unix command I pass the output into) only output the email ad...

Why does my Perl script fail on "~/" but works with "$ENV{HOME}"?

I have been using this script of mine FOREVER and I have always been using "~/" to expand my home directory. I get into work today and it stopped working: #if ( $output eq "" ) { $output = "~/tmp/find_$strings[0].rslt" } # BROKEN if ( $output eq "" ) { $output = "$ENV{HOME}/tmp/find_$strings[0].rslt" } #WORKS ... open OUT_FILE,...

Redirecting FORTRAN (called via F2PY) output in Python

Hi, I'm trying to figure out how to redirect output from some FORTRAN code for which I've generated a Python interface by using F2PY. I've tried: from fortran_code import fortran_function stdout_holder = sys.stdout stderr_holder = sys.stderr sys.stdout = file("/dev/null","w") fortran_function() sys.stdout.close() sys.stderr.close() sys...

How do I reliably track child/grandchild processes on a POSIX system?

I have an interesting (at least to me) problem: I can't manage to find a way to reliably and portably get information on grandchildren processes in certain cases. I have an application, AllTray, that I am trying to get to work in certain strange cases where its subprocess spawns a child and then dies. AllTray's job is essentially to d...

Should a directory path variable end with a trailing slash?

When defining a path to a directory as a variable or constant, should it end with a trailing slash? What is the convention? pwd in unix shows your current directory without a trailing slash, while the tab complete of cd /var/www/apps/ includes the trailing slash, which left me unsure. ...