unix

how do you normalize a file path in bash?

I want to transform "/foo/bar/.." to "/foo" Is there a bash command which does this? ...

How can I print the lines in STDIN in random order in Perl?

I want to do the inverse of sort(1) : randomize every line of stdin to stdout in Perl. ...

How do you do Cygwin passwordless rlogin or rsh to Solaris 5.7

I am trying to login in to my works Solaris box from cygwin on windows. SSH is not supported. I have tried different combination in the .rhosts with no luck I do not have root privileges. ...

How do you split a file base on a token?

Let's say you got a file containing texts (from 1 to N) separated by a $ How can a slit the file so the end result is N files? text1 with newlines $ text2 $etc... $ textN I'm thinking something with awk or sed but is there any available unix app that already perform that kind of task? ...

How can I find out which library is home to a given object?

I'm programming in FORTRAN and C on an SGI running Irix 6.5, but this should be applicable to all Unix-like systems. How do I find which library I need to link to my program when I get an "unresolved text symbol" link error? Here's an example of what I'm seeing from the linker: ld32: ERROR 33 Unresolved text symbol "ortho2_" -- first...

How do I find userid by login (Python under *NIX)

I need to set my process to run under 'nobody', I've found os.setuid(), but how do I find uid if I have login? I've found out that uids are in /etc/passwd, but maybe there is a more pythonic way than scanning /etc/passwd. Anybody? ...

Shortest command to calculate the sum of a column of output on Unix?

I'm sure there is a quick and easy way to calculate the sum of a column of values on Unix systems (using something like awk or xargs perhaps), but writing a shell script to parse the rows line by line is the only thing that comes to mind at the moment. For example, what's the simplest way to modify the command below to compute and displ...

`(cd X; pwd)` sometimes returns two-line

I have shell script which starts with: sdir=`dirname $0` sdir=`(cd "$sdir/"; pwd)` And this usually gets expanded (with 'sh -h') into ++ dirname /opt/foo/bin/bar + sdir=/opt/foo/bin ++ cd /opt/foo/bin/ ++ pwd + sdir=/opt/foo/bin but for single user for single combination of parameters in expands into (note two lines at the result ...

zcat won't unzip files properly

Hi, I need to unzip a compressed file on the fly in my program. It works when I try it on my own linux computer, but for some reason the school computers fail whenever I tell them to do it. To unzip I'm using the following command: zcat /file/address/file.tar.gz and get the error: /file/address/file.tar.gz.Z: No such file or dir...

Need for troubleshooting in UNIX w/ shell script program and IF..THEN command.

Since you guys are having lots of questions or not enough info to work with, below is proprietary information and as such be careful as you can. The question – (please refer to if [$7 -eq "AAA"]...then statement - in bold ) has a problem with an output, where I can only output/print count of 'AAA' regardless the variable coming in eith...

How to get the current directory in a C program?

I'm making a C program where I need to get the directory that the program is started from. This program is written for UNIX computers. I've been looking at opendir() and telldir(), but telldir() returns a off_t (long int), so it really doesn't help me. How can I get the current path in a string (char array)? ...

How do you use newgrp in a script then stay in that group when the script exits.

I am running a script on a solaris Box. specifically SunOS 5.7. I am not root. I am trying to execute a script similar to the following: newgrp thegroup << FOO source .login_stuff echo "hello world" FOO The Script runs. The problem is it returns back to the calling process which puts me in the old group wit...

Files being used by a unix process

The fuser command lets me know which processes are using a file or directory. I'm looking for command that does the opposite: lets me know which files are being used by a process. Update Forgot to mention that it's for a Solaris system. ...

Remote Unix Terminal Key Mapping

This has always bugged me. When I ssh or telnet to a Unix server (whatever flavour) it always manages to guess correctly the terminal type I am logging in from and so the keyboard always acts 'normally' ... i.e. the backspace key works. But then when I have successfully logged in, it often guesses incorrectly the terminal type I am usi...

How to resolve AIX tar command sockets errors?

Working in an AIX environment, I'm issuing the following tar command and receive errors on sockets. Question 1. How can I avoid the socket errors? Question 2. Can I rely on the tar file to contain all files excluding the ones in error? $ tar -cvf /post_patches.tar /xyz tar: /xyz/runtime/splSock6511 could not be archived tar...

Difference between using fork/execvp and system call

Hi What is the difference between using system() to execute a binary and using the combination of fork/execvp. Is there any security/portablility/performance difference. ...

What would be the simplest way to deal with a text file using JSP?

First and foremost I should acknowledge that I have no experience at all using Java ServerPages, but I'm positive about achieving this task if you guys help me out a bit since it doesn't seem like something difficult for a seasoned JSP programmer. Anyway the thing is, there's an actual running JSP application within a *NIX box which I s...

What's the best way to check that environment variables are set in Unix shellscript

I've got a few Unix shell scripts where I need to check that certain environment variables are set before I start doing stuff, so I do this sort of thing: if [ -z "$STATE" ]; then echo "Need to set STATE" exit 1 fi if [ -z "$DEST" ]; then echo "Need to set DEST" exit 1 fi which is a lot of typing. Is there a more el...

built in unix / linux command for recursive find and replace?

Many people string together find and sed, or perl, or any number of other unix commands to find and replace across multiple files. But, there's a simple command that can do it for you without the hassle. Thanks to The Digital Ninja for pointing out that it's rpl. This is not a built in command but, for debian based distros like Ubuntu ...

How to check if a var is a number in UNIX shell

The title says it all - How to check if a variable contains a number in UNIX shell? ...