unix-programming

dos / unix programming commands with | beginners question

Hi, I'm trying to do the following: get the last line of a file: tail -n 1 test.csv if this last line is END then continue(point 3), else quit get the amount of lines in the file: wc -l test.csv put these lines in a new file without the last line: head -n (length -1) test.csv > testdone.csv (or if it's possible delete ONLY this line...

Is it possible to create a script to save and restore permissions?

I am using a linux system and need to experiment with some permissions on a set of nested files and directories. I wonder if there is not some way to save the permissions for the files and directories, without saving the files themselves. In other words, I'd like to save the perms, edit some files, tweak some permissions, and then rest...

Sort lines by length with automator?

I have a text document (1MB, TXT file) with a little more than 17,500 lines. What I'm hoping to be able to do is to sort those lines by character length and have it output to either the same file (which is then saved) or a new file entirely. Either one works fine as long as I know ahead of time. Bonus points if I could do it through Aut...

java file move high performance

Hi, I am writing a media transcoding server in which I would need to move files in the filesystem and till now I am in the dilemma of whether using java renameTo can be replaced by something else that would give me better performance. I was considering using exec("mv file1 file2") but that would be my last bet. Anyone has had similar ex...

File sorter in unix

The code should sort the files in the given directory like the "ls" command. Please find exact details below:- File name in alphabetical order, size, mod time. The sort should continue if there is a sub directory. Please reply to this post. Its a bit urgent. Thanks, ...

Multiprogramming in Unix

Hello. I have some problems trying to make a simple program using execlp, fork and pipes. The program at hand is supossed to do "last |head -5| sort" but it doesn't work. Here is the code. #include <string.h> #include <fcntl.h> #include <stdio.h> #include <errno.h> #include <sys/types.h> #include <sys/stat.h> //last |head -5| sort int ...

Encyption SERVER using FIFO

A code that must have one server and five clients. Ten fifos and a pair of fifo for each client to communicat with the server. The client sends a file name (it has some contents which is stored on the disc) the server reads the contents and encrypts the contents using XOR with 'a' and sends back to the client. The client then reads the c...

using mount(2) function in C

I've have been desperately searching for a tutorial on how to use the mount() function properly (they are very good at hiding this knowledge). I need to use it to MNT_UPDATE " / "(/dev/disk0s2 in this case) in single user mode but I can't find an example or tutorial on how to use the function. ps. Please no "Use system()" pps. I know /...

Sending a C char array over a socket

I want to send a character array over a tcp socket in unix. My first idea was to use an ordinary char array for the struct that will be sent over the socket: typedef struct __attribute__((packed)) { uint8_t type; uint8_t id_index; char char_value[STR_MSG_MAX]; } a_msg; Simply because a C char is always 8 bit long. However, a...

Getting cmos time in C on Freebsd?

EDITED 8/18/2010 I have C code for Linux that, among other things, caches the difference between the rtc and system time. I want to port this code to FreeBSD/Mac. Linux has the utility hwclock which reads /dev/rtc and anyway getting the cmos clock time directly from this interface can be done in a few lines of code. I've been lookin...

Using su in Shell script

Hi All, I am writing a shell script where in a condition the script will change the user like su - xxx and then it has to execute some commands/scripts and should stay login to that user/session for user interaction. Once user enter exit it should exit from that session and should return to script. I have tried using su - xxx -c "comman...

Can someone recommend a good unix syslog *client* library for java?

java.util.logging.Logger seems to implement "syslog-like" logging, where I want the logs to actually use the local syslog logging fascilities (so life is easier for admins; they don't have to do extra log rotation, etc.). Anyone have any recommendations? I saw that log4j (http://logging.apache.org/log4j/1.2) claimed they had syslog sup...

Problems creating and binding port in unix. (New to network programming)

Hi, I'm having trouble creating a port in Unix. This code keeps returning "Error creating socket (3)", which makes no sense whatsoever, since sockfd must be smaller than 0 to print the error line. server.c: int main (int argc, char **argv) { int sockfd; struct sockaddr_in server_sockaddr; char buff[TRANSFER_BUFFER_LEN]; /* che...

How to convert a tab separated file into comma separated file

Hi i want to convert a tab separated file into csv file can anyone help me ...

Determine whether a file is on NFS using system programming.

I need to determine if a file resides in NFS in my C program. I know there are several ways to do that differently on Linux, Solaris etc but I need to write a program which works on all Unix platforms like Solaris, AIX, HPUX along with Linux and Windows (if possible). I don't think i will be able to find something compatible with Window...

Socket programming at low level

Hi, I am unable to understand or grasp rather; what it means to program at a lower layer in socket programming. I am used to working with tcp/udp/file system sockets. These are all wrapped around their own protocol specifications ... which as i understand would make it working at the application layer in the stack. In the project i am ...

Matlab-like command history retrieval in unix command line

In Matlab, there is a very nice feature that I like. Suppose I typed the command very-long-command and then a few several commands afterwards. Then later if I need the long command again, I just type very and press the up arrow key, my long command appears. It finds the last command that starts with very. I couldn't do the same in un...

How to make a shell script global?

I am on Mac's OS 10.6, and I am trying to learn a thing or two about shell scripting. I understand how to save a shell script and make it executable, but I am wondering what I can do or where I can save the file to make it global (that is, accessible no matter what folder I am in). For example, if I save a .sh file in the /Users/usernam...

How do unix-like OS implement IPC shared memory?

Hi, guys. I am wondering how do unix-like OS implement shared memory? What is difference between accessing a normal user-space memory between accessing a memory unix in sytem IPC shared memory? ...

Struct that apparently defines no instances in Unix v6

I'm going through the code of Unix version 6 with the Lion's book. One of the header files (param.h, can be accessed here) defines the following structs: /*struct to access integers*/ /*single integer */ struct { int integ; }; /*in bytes*/ struct { char lobyte; char hibyte; }; These structures don't seem to define any instance, nor...