unix

How can I use the shell's process substitution in Perl's system()?

Why does this line of Perl break? system("paste <\( cut -f2 $file \) $file2 > $fileout"); What's the correct way to do it? ...

Renaming multiple files: mv changing_part_footer.php changed_part_footer.php

I have files: hallo_flower.php hallo_house.php I need to rename them to: tjena_flower.php tjena_house.php ...

How to execute the output of a command within the current shell?

Hi, I'm well aware of the source (aka .) utility, which will take the contents from a file and execute them within the current shell. Now, I'm transforming some text into shell commands, and then running them, as follows: $ ls | sed ... | sh ls is just a random example, the original text can be anything. sed too, just an example for...

Removal after some Iterations: yes | rm -r .git

I need to kill the "yes" command after some iterations, two methods: a) kill it b) give "n" as an input after some time How would you automate the removal of .git directory? ...

Converting unix timestamp to YYYY-MM-DD HH:MM:SS.

I have a Unix timestamp that I need to get the individual year, month, day, hour, minute and second values from. I never was very good in math class so I was wondering if you guys could help me out a little :) I have to do everything myself (no time.h functions). The language is C. ...

Does getpwnam respect /etc/nsswitch.conf?

Does getpwnam respect /etc/nsswitch.conf? The manpage for getpwnam states The getpwnam() function returns a pointer to a structure containing the broken-out fields of the record in the password database (e.g., the local password file /etc/passwd, NIS, and LDAP) that matches the username name. This leads me t...

What shell am I in?

If I'm in a shell script that has no shebang line… Hum, that doesn't matter, because indeed sh is always used. Maybe not so. Is there a command to identify the name/type of current shell, the path to the shell binary, and the version of the shell? I don't need all of that, but the more I can get, the better. I want something that has ...

Configure Apache to use different Unix User Accounts (www-data) per Site.

An Apache 2.x Webserver with default configurations from the ubuntu/debian repositories will use the www-data unix account for apache2 processes handling web requests. Assuming that apache is serving two different sites (domain1.com and domain2.com), is it possible for apache to use unix user www-data1 when handling requests to domain1.c...

How to use cronjob

I have my application hosted on a shared web host which uses cpanel. The control panel has a web interface to cronjob. I want to use cronjob to execute a file at a certain time everyday. The challenge am having now is the right command to enter in the "Command to run" text box. I'll be very glad if someone can help me out with this. Tha...

On Linux, how do I recursively copy files while ignoring certain names?

I need to recursively copy a directory tree, ignoring any subdirectories named 'CVS'. Is there a simple way to do this? ...

ftp file from server1 to server2 in unix

i am a shell scripting noob. i currently have a cronjob that runs every 15mts and check to see if a file exists. If it exists, it takes the file and processes and then deletes it Now, instead of deleting it, i want to make a copy and ftp it to Server2 below is the delete script. i want to modify it so that it makes a copy of the file...

How to write frames to a video file?

I am currently writing an application that read frames from camera, modify them, and save them into a video file. I'm planing to do it with ffmpeg. There's rarely a documentation about ffmpeg. I can't find a way. Does any know how to do it? I need it to be done on unix, and in C or C++. Does any can provide some instructions? Thanks. ...

Find all files in a directory that are not directories themselves.

I am looking for a way to list all the files in a directory excluding directories themselves, and the files in those sub-directories. So if I have: ./test.log ./test2.log ./directory ./directory/file2 I want a command that returns: ./test.log ./test2.log and nothing else. ...

How can I display the execution status of the command "ssh-copy-id" from Perl?

I have a Perl script which does this: It generates a ssh authentication key on my system and then copies this key to a remote Linux system for passwordless ssh connects. The code is as below: # Generate an rsa key and store it in the given file system("ssh-keygen -t rsa -N '' -f /root/.ssh/id_rsa 1>/dev/null"); # Copy the generated ke...

How do I check for the existence of a file using a wildcard in Bourne shell?

What I'm looking for is something like: if [ -f "filenam*" ]; then ... fi But the wildcard (*) causes problems. I've also tried: if [ `ls filenam* > /dev/null 2>&1` ]; then ... fi Which may work in other shells but doesn't appear to work in Bourne shell (sh). Thanks for any help! EDIT: Sorry, not C shell, Bourne shell (s...

How to write a unix script that gets notified with IMAP IDLE from Gmail?

I'm looking for a way to get notified in my unix system for new email. I know gmail supports IMAP IDLE, what is the best way to make use of that feature? Any programming language is fine, as long as it is supported in linux/unix. ...

Cron job stderr to email AND log file?

I have a cron job: $SP_s/StartDailyS1.sh >$LP_s/MirrorLogS1.txt Where SP_s is the path to the script and LP_s is the path for the log file. This sends stdout to the log file and stderr to my email. How do I?: 1) send both stdout AND stderr to the logfile, 2) AND send stderr to email or to put it another way: stderr to both the logf...

Launch a child process on OSX/Unix that doesn't inherit files/ports

I want to launch a child process on OS X such that the child process does not inherit the current process's open files/ports. Any suggestions on how to accomplish this? Shell commands that I can invoke using the system() function would work too - I just don't know of a good shell command that enables this. Thanks! ...

Program can't load after setting the setuid bit on

Consider this scenario in which an executable A.bin uses libY.so and libZ.so. A.c, Y.c and Z.c are all written in C. Z.c and Y.c are compiled into respective .so files. This is the directory structure of the files $home/bin/A.bin $home/lib/libY.so $home/lib/libZ.so When I run A.bin as normal user, A.bin runs normally as expected. Note...

Closing all open files in a process

How do I find all the open files in a process (from inside itself)? This seems useful to know after a fork() (before exec()). I know of the existance of getdtablesize() and the more portable sysconf(_SC_OPEN_MAX), but it seems inefficient to attempt closing every valid file descriptor, whether there's an open file behind it or not. (I ...