I have a process that's writing a lot of data to stdout, which I'm redirecting to a log file. I'd like to limit the size of the file by occasionally copying the current file to a new name and truncating it.
My usual techniques of truncating a file, like
cp /dev/null file
don't work, presumably because the process is using it.
Is th...
In my web application I render pages using PHP script, and then generate static HTML files from them. The static HTML are served to the users to speed up performance. The HTML files become stale eventually, and need to be deleted.
I am debating between two ways to write the eviction script.
The first is using a single find command, lik...
what condition is being checked below?
if [[ ! -s ${FILE} || -z ${FILE} ]]
(here $FILE is a data file)
...
I'm writing a small read-only FTP-like server. Client says "give me that file" and my server sends it.
Is there any standard way (a library function?!?) to make sure that the file requested is not "../../../../../etc/passwd" or any other bad thing? It would be great if I could limit all queries to a directory (and its subdirectories).
...
I have two files where I want to perform union operation
based on 1st column:
file1.txt
foo 1
bar 2
qux 3
file2.txt
foo x
qux y
boo z
The result I hope to get is like this:
foo 1 x
bar 2 -
qux 3 y
boo - z
where the empty fields of column 1 is padded
with "-".
But why this join command doesn't work as I expected?
$ join -a...
In many programs and man pages of Linux, I have seen code using fork(). Why do we need to use fork() and what is its purpose?
...
Guys, is there an alternative to "tee" which captures STDOUT/STDERR of the command being executed and exits with the same exit status as the processed command. Something as following:
eet -a some.log -- mycommand --foo --bar
Where "eet" is an imaginary alternative to "tee" :) (-a means append, -- separates the captured command) It shou...
In bash, is there a way to chain multiple commands, all taking the same input from stdin? That is, one command reads stdin, does some processing, writes the output to a file. The next command in the chain gets the same input as what the first command got. And so on.
For example, consider a large text file to be split into multiple files...
I need to wrap the Unix command "tail -f" in a BufferedInputStream. I don't want to simulate or mimic tail as stated by this question. Rather, I want to use tail, waiting for it to give me a new line.
...
I have built an application with PHP which shows all the files in the home directory of a user this directory is also available via samba so you can access it from the native explorer in windows, mac and linux. I wanted to give every file an ID so that I can asign tags to every file how would you go about doing this? Would you make hashs...
According to Wikipedia, the following is a very elegant bash fork bomb:
:(){ :|:& };:
How does it work?
...
I've got a c++ application with certain items in a queue, those items then are going to be processed by a python script. I want it so that at maximum 10 instances of the python script are running. I plan on using execl() to launch the python process, Is there a way to tell that the process has quit without having to pass a message back t...
Hi,
We have a c file called dbookpy.c, which will provide a Python binding some C functions.
Next we decided to build a proper .so with cmake, but it seems we are doing something wrong with regards to linking the external library 'libdbook' in the binding:
The CMakeLists.txt is as follows:
PROJECT(dbookpy)
FIND_PACKAGE(PythonInterp)...
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <arpa/inet.h>
int main(int argc, char *argv[])
{
//set up hints
struct addrinfo hints;
struct addrinfo *res;
struct sockaddr their_addr;
socklen_t sin_size = sizeof their_addr;
...
If not why not? It seems as though reading, writing, and appending to it would be far more flexible provided multi instance and multi-user issues are accounted for.
...
How can I create a directory link that will survive git submodule update?
Given the following example directory structure:
proj
|-- lib3
| `-- submod
| `-- lib
`-- lib
I created a soft link from proj/lib/ to proj/lib3/submod/lib using something like the following command:
brad@bradpc:~/proj/lib$ ln -s ../lib3/submod/lib subm...
How can I find out who executed a particular command and which terminal was used to run it?
Original:
how can i know particular cmd is executed by whom and to know about my terminal
...
In my .zshrc, I use the following snippet to integrate the shell's clipboard and my primary X11 clipboard. Thanks to this integration, I can cut-and-paste text to and from emacs, firefox, and the terminal without having to use the mouse.
kill-line() { zle .kill-line ; echo -n $CUTBUFFER | xclip -i }
zle -N kill-line # bound on C-k
yank...
I am working on adding some nagios alerts to our system -- some of which will monitoring the rate of certain events hitting the nginx/apache logs (or parsing values from those logs.) The way I've approached the problem so far is with a simple shell script tail -f'ing the log for 25 seconds or so to a temporary file, killing the process, ...
I would like to create a script that automatically logs into a remote server and grabs a file on the server. The script already logs into the server however the commands are not run on that machine. Once I disconnect from the remote server, the commands are run on the client machine.
!/bin/sh
ssh -o PreferredAuthentications=publickey b...