unix-programming

How to read a value in UNIX

Hi, I am new to UNIX and can’t figure out how to access a certain number from a file. Following is the result I get when I type in quota -v. I need to write a script to check and make sure if I am under quota, if not display a warning message. So, I am wanting to access “usage” number and “limit” number from that file and use a 'if' s...

How to remove words from a file in UNIX?

first file of information page name/joe/salary1 50 10 2 name/don/miles2 20 4 3 name/sam/lb3 0 200 50 can some one please tell me how can I remove all the words in the above file, so my output will looks as follows 50 10 2 20 4 3 0 200 50 ...

where does the shared memory gets allocated?

In Linux, When we are sharing data between 2 or more processes using shared memory, where does the shared memory gets allocated? Will it become part of process address space at run time? as the process cannot access the memory outside its address space. Could some one please clarify? ...

UNIX, Assign value to a variable in C or Korn shell

Hi, when I use bash to run the following code, it will assign the value 5 in to the var1. var1=$(awk '$1>$3{ print "5"}' newfile2) echo $var1 But when I use this same code in banana or something, it gives me error. Can some one please tell me if there is some other way I can write this code, so I can run it using the C or Korn shell ...

Unix Script to Process multiple file names

I'm writing a script that will fold, sort and count text in a file. I need to design the program so that, if it is given multiple filenames on the command line, it processes each one separately, one after the other. I think I could write a loop but I don't know that much about those yet so if possible would like to try other options. Are...

POSIX seekdir() and telldir() behaviour after target folder modification

Hello, consider the following task : 1) read a target directory contents, pass each found dirent structure to some filter function and remember filtered elements somehow for the later processing 2) some time later, iterate through the filtered elements and process them (do some I/O) The most obvious way is to save names of sub-direc...

Print columns with Awk or Cut?

I'm writing a script that will take a filename as an argument, find a word a specific word at the beginning of each line - the word ATOM, in this case - and print the values from specific columns. $FILE=*.pdb * if test $# -lt 1 then echo "usage: $0 Enter a .PDB filename" exit fi if test -r $FILE then grep ^ATOM $FILE | awk '{ print ...

how to use ctrl-D in a shell script

Hi Everyone, I have a bash shell script that requires ctrl-D to break out of the terminal.can anyone tell me how to use it in the shell script example ssh host last --->displays the list of users who were logged on to that host i have different hosts the output is appended to one final and when i'm executing this particular shell s...

Cannot append to file when some other process writes to it on *nix systems

I have a very simple piece of code which just writes a small amount of data to a file at some regular interval. Once my program has created the file and appended some data, when I open this file in vim(or any other editor for that matter) and edit it, my process cannot seem to update the file anymore. I do not see any errors being return...

protocol sniffer

i have to do a project of over protocol sniffer. would you help me for this, actually i have to build a app which can show the all ports opening on a specific file...it means i m gonna to browse a file (for example music file is at there) so this music file is use like multitasking (aomeone download them and someone listining that song a...

how to pass file as an argument to the script file

Hi Everyone, I have a shell script written in bash and this script should take file as an argument,can any one tell me how to write script for this any ideas on this are apprecited Thanks, ...

Regarding grep command

I have two queries I do a grep and get the line number of the input file. i want to retrieve a set of lines before and after the line number from the inputfile and redirect to a /tmp/testout file. how can i do it. I have a line numbers 10000,20000. I want to retrieve the lines between 10000 and 20000 of the input file and redirect ...

Develop a shell script to find a folder in the directory and compress it

Im new to unix shell script i need to develop a shell script a) To find called the folder called essbase in the directory /olap/Analytics/App/essbase b) essbase folder should be tar or compress it move to another directory /crd/dw/fin C) When the user request the essbase folder compress file should be moved back to the location orgin...

open() causes program termination

Hi, I use the following program to write to a fifo: #include <iostream> #include <fstream> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> #include <fcntl.h> #include <sys/types.h> #include <sys/stat.h> using namespace std; int main() { unlink("fifo1"); if (mkfifo("fifo1", 0666) != 0) { ...

Taring the Folder script not working in Aix

GNU commands like maxdepth are not working for Aix ,Alternate command for Taring the folder # THIS SCRIPT BEGINS HERE # Check for the all folders in the Directory find /fss/fin -type d -name "*" -print Tar the Folders in the current directory and Move it into separate directory (cd /fss/fin; find * -maxdepth 0 -type d -print 0 | x...

mkfifo Alternative

Hi there, I have a process that continuously needs to write information. Furthermore, there is a second process which sometimes connects to the "information channel" of the writing process and should read the information that are written since it's connected. This process might also deconnect and reconnect several times again. I am cur...

Getting file modification time on UNIX using utime in C.

I have been told by a professor that you can get a file's last modification time by using utime.h. However, the man page seem to cite that utime() only sets this value. How can I look up the last time a file was changed in C on a UNIX system? ...

OS X script to send email when new file is created

How can I monitor a directory, and send an email whenever a new file is created? I currently have a script running daily which uses find to search for all files in a directory with a last modified date newer than an empty timestamp file: #!/bin/bash folderToWatch="/Path/to/files" files=files.$$ find $folderToWatch/* -newer timestamp -p...

Shell script problem to set my env

We have few executable which need some environment setting. We manually running those scripts before running the executable Like $ . setenv.ksh We have to encompass call these in one script to avoid the manual work. We written a sh script like #!/bin/sh . setenv.ksh ./abc & Still the environments are not setting in that session...

Problem with awk and grep

I am using the following script to get the running process to print the id, command.. if [ "`uname`" = "SunOS" ] then awk_c="nawk" ps_d="/usr/ucb/" time_parameter=7 else awk_c="awk" ps_d="" time_parameter=5 fi main_class=RiskEngine connection_string=db.regression AWK_CMD='BEGIN{printf "%-15s %-6s ...