unix

Copy folder recursively, excluding some folders

I am trying to write a simple bash script that will copy the entire contents of a folder including hidden files and folders into another folder, but I want to exclude certain specific folders. How could I achieve this? ...

Process.daemon vs. running a Ruby script with nohup + &

I have a Ruby 1.9 script that I want to run as a long-running background process. It looks like I have a choice between calling Process.daemon inside the script to daemonize it, or I can just run the script in the background using a shell's ampersand and keep it running after I log out of the server by prefixing the command with nohup....

Best way to copy and duplicate each line of input file while regex modifying the duplicated line.

This question has 2 sections one for "single line match" and one for "multi line region matching" Also, I have a semi working solution, I want to find more robustness and elegance in my solution. Single Line Match: I would like to duplicate each line of an input file such that the second line was a regex modification of the first: E.G...

Cross platform way of testing whether a file is a directory

Currently I have some code like (condensed and removed a bunch of error checking): dp = readdir(dir); if (dp->d_type == DT_DIR) { } This works swimmingly on my Linux machine. However on another machine (looks like SunOS, sparc): SunOS HOST 5.10 Generic_127127-11 sun4u sparc SUNW,Ultra-5_10 I get the following error at compile time...

Passing Bourne Shell var into cut command

I am trying to do the following. foo="foo:foo1" cc= `$foo | cut -f2 -d:` I understand why this would not work but I am at a loss as to do this. Thanks in advance. ...

Bash - How to call a function declared in a parent shell?

I am writing a bash script that calls functions declared in the parent shell, but it doesn't work. For example: $ function myfunc() { echo "Here in myfunc" ; } $ myfunc Here in myfunc $ cat test.sh #! /bin/bash echo "Here in the script" myfunc $ ./test.sh Here in the script ./test.sh: line 4: myfunc: command not found $ myfunc Here ...

Is 0 or 1 valid return values for socket() function call

Could the socket function call in C return 0 or 1 as the value for the socket descriptor? int socket(int domain, int type, int protocol); According to the man page I have: RETURN VALUE -1 is returned if an error occurs; otherwise the return value is a descriptor referencing the socket. It seems like it could, or at l...

What does phrase "Reuse of local addresses is supported" mean?

In The Single UNIX Specification, Version 2 http://www.opengroup.org/onlinepubs/007908799/xns/syssocket.h.html claims that the param value of SO_REUSEADDR in setsockopt means: "Reuse of local addresses is supported". Can some clarify me that phrase? ...

ssh-agent and crontab -- is there a good way to get these to meet?

I wrote a simple script which mails out svn activity logs nightly to our developers. Until now, I've run it on the same machine as the svn repository, so I didn't have to worry about authentication, I could just use svn's file:/// address style. Now I'm running the script on a home computer, accessing a remote repository, so I had to c...

Automate Java installs on Unix

I'm currently working on self bootstrapping/configuring deployments for J2EE applications. My goal is to have the deployment install Java, App Server, and app deployment every time. Unfortunately I'm running into problems automating the java install. The java install is provided as a self-extracting binary (ie. jre-6u18-solaris-sparc.sh...

How to have git repository in NFS partition and working-tree in local partition?

My home directory is in a remotely-mounted NFS partition on a file-server and is routinely backed-up. I would like to have my project's git repository be under my home directory (so that it's backed-up) but I would like my working-tree to be in a local disk partition of my workstation (so that building is fast). The local disk partitio...

Struggling to use calloc and realloc to initialize arrays in C.

Hello, I'm struggling to use calloc and realloc for my array initializations. I'm trying to write a program which calculates a final sum from the command line arguments using fork() with a companion program. If I receive a odd set of integers from the command line such as: ./program 1 2 3 4 5. It should see that amount is odd and ini...

Thread limit in Unix before affecting performance

I have some questions regarding threads: What is the maximum number of threads allowed for a process before it decreases the performance of the application? If there's a limit, how can this be changed? Is there an ideal number of threads that should be running in a multi-threaded application? If it depends on what the application is do...

[C - fdopen] Possible Bug - Associating a stream with a FD that already has one associated with it?

Howdy. I am in a networking class and we are creating our own "networking API" using the socket functions we have learned in class thus far. For the assignment the professor provided the already complete chat and server programs and we were to fill in a blank .c file that had an associated header file that described the function calls i...

Trouble using fork() to calculate a total sum of received command line arguments.

I'm trying to calculate the sum based off of sets of numbers received from the command line and I use a companion program called worker to due the computation for me. If the amount of numbers received is odd, it will add a zero to the amount of numbers to make the set even. This is the flow of the program in an understandable way(credit...

Collecting the output of an external command using OCaml

What is the right way to call an external command and collect its output in OCaml? In Python, I can do something like this: os.popen('cmd').read() How I can get all of an external program's output in OCaml? Or, better, OCaml with Lwt? Thanks. ...

How to get vi keybindings to work in mysql client?

I have vi bindings working in my bash shell using set -o vi in my .bash_profile. But I can't seem to get them to work in the mysql command line client. I only get emacs style bindings. How do you do this? I also put these lines in my .inputrc, but to with no effect: set editing-mode vi set keymap vi ...

Check for UNIX command line arguments, pipes and redirects from a C program.

Hi, I have some problem to figure out how I can maintain the pipe and redirect functionality of a shell once I find out that there are missing command line arguments. If I for example use a scanf call, that will work with a re-direct or a pipe from a shell, but in absence of this I get a prompt, which I don't want. I would like to ac...

How to implement alarm() method correctly to kill all worker processes created by fork()?

If I have a parent coordinator program and a worker program, but the coordinator program is creating all of the needed worker processes. If I want to implement the alarm() method correctly to kill all of the processes and terminate the program after a certain amount of time. Is this the correct way to implement it? The current way I hav...

gdb: breakpoint when register will have value 0xffaa

Can I set the breakpoint/watchpoint/smth else in gdb for register value? I want to break when $eax will have value 0x0000ffaa. Is it possible with gdb or dbx or any other unix debugger? ...