unix

Problem with blocking unix domain sockets

I'm writing an application that is split into two parts for Mac OS X - a daemon and an agent. I'm using a standard unix socket to communicate between the daemon and the agents. That is, the socket is created with PF_UNIX and SOCK_STREAM. When agents are created (whenever a user logs in), one of the first things it does is to connect to...

Using BASH - Find CSS block or definition and print to screen

I have a number of .css files spread across some directories. I need to find those .css files, read them and if they contain a particular class definition, print it to the screen. For example, im looking for ".ExampleClass" and it exists in /includes/css/MyStyle.css, i would want the shell command to print .ExampleClass { color: #ff00...

How do you feed in an entire directory of input files using cat in Unix?

I'd like to run a program on a directory of files. I know how to do this with one file, using cat myFile.xml | myProgram.py. How can I run myProgram.py over a folder, say myFolder? Thanks! ...

Redirect stdin in C program to another process

I have a C program, and I'd like to have it filter all its input with tr. So, I'd like to start up tr as a child process, redirect my stdin to it, then capture tr's stdout and read from that. Edit: here's the code I have so far, which doesn't work. It segfaults instantly, but I don't understand why: #include <stdlib.h> #include <stdio....

Calling another process from python/child process need to access shell

Hi, I'm calling a C/C++ program from python with Popen, python code should observe behavior of child process and collect some data for his own work. Problem is that C code already uses pipes for calling some shell commands - so after my execution from python, C program cannot execute bash shell command. Is there any way in calling fro...

MySQL - Combine two fields to create a unix timestamp?

Hi, I'm trying to retrieve a UNIX timestamp from a query by combining a date and a time field in the table, however it keeps returning as zero. SELECT *, UNIX_TIMESTAMP(startdate starttime) AS start, UNIX_TIMESTAMP(enddate endtime) AS end FROM mytable; Can anyone help me out? Thank...

Unix: replace every odd | with \left| and every even | with \right|

An enormous equation. You need to add \left| on the left side of corresponding |. The corresponding | you need to replace with \right|. Equation \begin{equation} | \Delta w_{0} | = \frac{|w_{0}|}{2} \left( |\frac{\Delta g}{g}|+|\frac{\Delta (\Delta r)}{\Delta r}| + |\frac{\Delta r}{r}| +|\frac{\Delta L}{L}| \right) \end{equation} [Pr...

sed/awk or other: one-liner to increment a number by 1 keeping spacing characters

EDIT: I don't know in advance at which "column" my digits are going to be and I'd like to have a one-liner. Apparently sed doesn't do arithmetic, so maybe a one-liner solution based on awk? I've got a string: (notice the spacing) eh oh 37 and I want it to become: eh oh 36 (so I want to keep the spacing) Using awk I don't fi...

AWK: how to read columnwise file to AWK-script in Bash?

$ cat read.sh #!bin/bash // how can I read the columnwise data to awk-script? awk '{sum+=$1} END {print sum}' read $ cat data 1 2 3 4 5 $ . ./read.sh <data awk: cmd. line:1: fatal: cannot open file `read' for reading (No such file or directory) ...

How do I grep for entire, possibly wrapped, lines of code?

When searching code for strings, I constantly run into the problem that I get meaningless, context-less results. For example, if a function call is split across 3 lines, and I search for the name of a parameter, I get the parameter on a line by itself and not the name of the function. For example, in a file containing ... someFuncti...

How to convert date and time into unix timestamp in php?

echo $_POST['time']."<br/>"; echo $_POST['day']."<br/>"; echo $_POST['year']."<br/>"; echo $_POST['month']."<br/>"; I have value store like this now I want to create a timestamp from these value. How to do that in PHP? Thanks in advance ...

unexpected result from gnu sort

when I try to sort the following text file 'input': test1 3 test3 2 test 4 with the command sort input the output is exactly the input. Here is the output of od -bc input : 0000000 164 145 163 164 061 011 063 012 164 145 163 164 063 011 062 012 t e s t 1 \t 3 \n t e s t 3 \t 2 \n 0000020 1...

How to update Xcode to install "UNIX Development Support" ?

I installed Xcode a long time ago. Apparently I didn't check back then the "UNIX Developemtn Support" checkbox. Now I want to have them bu when I click on the installation this is what appears: The UNIX Development Support check box is disabled Q. ¿How can I install the UNIX Development Support? Is there a way to run some script ...

Unix Permisions: How do groups work in Unix

This is probably a dup (but did not find it..) When you type ls -l in unix you get output like this: % ls -l total 48 -rwxr--r-- ... change* -rwxrwxrwx ... checkVersion* -rwx------ ... info* I know that the first group of rwx sets the users permisions and the last group sets "everyone else's" permisions. I think that the secon...

Unix variable best practice: Should variable containing a path end in a slash

What is the best practice when storing a directory in a file name on a unix system? Should the directory path end in a slash? Method A TMP="/tmp/pasteTmp/" which allows you to do: cd "$TMP$fileName" Method B TMP="/tmp/pasteTmp" which allows you to do (with an extra slash which seems less clean): cd "$TMP/$fileName" but a...

Too many open files in one of my java routine.

I have a multithreaded code that has to generated a set of objects and write them to a file. When I run it I sometime get "Too many open files" message in Exception. I have checked the code to make sure that all the file streams are being closed properly. Here is the stack trace. When I do ulimit -a, open files allowed is set to 1024. W...

What is a reliable way to detect which line break characters are used in a file?

I'm reading text files but I don't know in advance the kind of line ending used in this file. I need to know whether it uses UNIX \n or windows style \r\n line endings. What is a reliable and fast way to detect this? ...

starting smartcard programming

How could one get started with smartcards programming? I am asking here about all the toolkit he needs in order to get started: books, tutorials, hardware etc. I am planning in playing around with a couple of smartcards programmers and I am pretty new to this field. Edit: I am mostly interested in programmers that play nice with Unix-l...

How to log a output(regular or error) of a unix program into a file

logging a output(regular or error) of a unix program into a file. ...

Installing Daemons

A simple link would be nice for me to understand how to install my C++ program as a daemon in UNIX, now I know some will say this should be on Server Fault, but as far as I understand it I need the init.d shell script to actually create the start and stop for the daemons. But if you guys can show me a simple shell script for the daemon ...