shell-scripting

What's the simplest way to pass a file as an argument in a simple shell script ?

The following works fine on Mac OS X: #!/bin/bash R CMD Sweave myfile.Rnw pdflatex myfile.tex open myfile.pdf Now, I realize that these 3 lines of code are really helpful for my work – independently of some particular file. Thus I'd like to use the file as an argument. I know how to use an argument itself but have problems splitting t...

What are the most important shell/terminal concepts/commands for novice to learn?

ALthough I've had to dabble in shell scripting and commands, I still consider myself a novice and I'm interested to hear from others what they consider to be crucial bits of knowledge. Here's an example of something that I think is important: I think understanding $PATH is crucial. In order to run psql, for instance, the PostgreSQL fo...

Two variables from a line

The corrupt table entry is logged in the error file something like this... /usr/local/mysql/bin/mysqld: Incorrect key file for table './accounts/headers.MYI'; try to repair it I want to write a query that will repair this table. REPAIR TABLE accounts.headers; What I need to do is search for the first instance of "./" an...

How to pass a variable FROM applescript TO a shell script ?

I have the following script #!/bin/bash /usr/bin/osascript << EOT set myfile to choose file EOT no_ext=$(python -c "print '$myfile'.split('.')[0]") ### this works - just need to know how to pass the arg R CMD Sweave no_ext.Rnw pdflatex no_ext.tex open no_ext.pdf Can anyone point me to "how to pass the variable myfile corre...

Is moving custom shell script to /usr/bin problematic?

Well, the title says it all. Is it dangerous, insecure or not-so-smart for any other reason to put a custom shell script to /usr/bin and add /usr/bin to $PATH in order to make a custom script executable from everywhere without ./ and the file extension? Bonus question: can I assign custom icons to custom executable scripts? ...

Words before and after selected text

My SQL query looks like this... sekect * FROM mail_headers a LEFT JOIN mail_headers_body b ON a.mailid=b.id blah blah blah I can select the lines before and after the result, using -A, -B switches. But how do I find the 4 words before and after the selected text? grep -i 'JOIN mail_headers_body' mysql-gen.log This will retur...

Sorting in bash

I have been trying to get the unique values in each column of a tab delimited file in bash. So, I used the following command. cut -f <column_number> <filename> | sort | uniq -c It works fine and I can get the unique values in a column and its count like 105 Linux 55 MacOS 500 Windows What I want to do is instead of sorting by th...

Set directory of files created by a shell script?

Dear all, EDIT: had to retag this, because, it's rather a Sweave / R question since the problem of this script is the output directory of the Sweave Code. Is there a corresponding option for R CMD Sweave ? I have a shell script that creates a .tex file from a .Rnw file. This file needs to be processed further, but is not found by the s...

Split big compressed log files into compressed chunks of X lines while doing inline compression

My situation is the following: a big (10GB) compressed file containing some files (~60) with a total uncompressed size of 150GB. I would like to be able to slice big compressed log files into parts that have a certain number of lines in them (ie: 1 million). I don't want to use split since it involves totally decompressing the original...

Avoid gnome-terminal close after script execution?

I created a bash script that opens several gnome-terminals, connect to classroom computers via ssh and run a script. How can I avoid that the gnome-terminal closes after the script is finished? Here is an example of my code: gnome-terminal -e "ssh root@ cd /tmp && ls" thx for your help ...

In a unix shell, how to get yesterday's date into a variable?

Hi, I've got a shell script which does the following to store the current day's date in a variable 'dt': date "+%a %d/%m/%Y" | read dt echo ${dt} How would i go about getting yesterdays date into a variable? Basically what i'm trying to achieve is to use grep to pull all of yesterday's lines from a log file, since each line in the lo...

sendmail time option

is there any option to sendmail linux command on particular time . I want make or sending email on particular time . ...

Replacing one XML element with another

I'm interested in finding out what's the shortest script one can write to replace one XML element in a file with another one from a second file. I can whip up a simple program to easily do this, but I'm wondering if it's easily do-able using a shell script. It's just a utility tool meant as a convenience. Can this be done using sed? awk...

How do I programmatically convert FLV video files to MP4 using a shell script in OS X?

I want to batch convert a directory containing hundreds of FLV files so that each file has a MP4 equivalent. I'm trying to automate this process by writing a shell script and running it from the Terminal. How do I go about doing that? Most of the instructions available are for Linux using ffmpeg but I think OS X doesn't have it. Thanks. ...

How do i have a cron run and check which crons are currently running

I have an ubuntu server that i have some scripts that need to run on a cron. The first is a shells script and the second is a php script. How do I check to see what is running currently on cron and how do I add these two files to run on cron daily or hourly. Not sure what the client needs yet. Is there a file i need to change. Any help w...

NoClassDefFoundError when running shell script

Here is the error: Exception in thread "main" java.lang.NoClassDefFoundError: org/alicebot/server/net/AliceServer Caused by: java.lang.ClassNotFoundException: org.alicebot.server.net.AliceServer at java.net.URLClassLoader$1.run(URLClassLoader.java:202) at java.security.AccessController.doPrivileged(Native Method) at java.net...

Batch renaming using shell script

I have a folder with files named as input (1).txt input (2).txt input (3).txt ... input (207).txt How do I rename them to input_1.in input_2.in input_3.in ... input_207.in I am trying this for f in *.txt ; do mv $f `echo $f | sed -e 's/input\ (\(\d*\))\.txt/input_\1.in/'` ; done But it gives me mv: target `(100).txt' is not a d...

Removing non-displaying characters from a file

$ cat weirdo Lunch now? $ cat weirdo | grep Lunch $ vi weirdo ^@L^@u^@n^@c^@h^@ ^@n^@o^@w^@?^@ I have some files that contain text with some non-printing characters like ^@ which cause my greps to fail (as above). How can I get my grep work? Is there some way that does not require altering the files? ...

What does the ∴ character do in a bash shell?

Stumbled across the ∴ operator in some of the rvm install scripts and couldn't seem to locate information on what it does? Is there documentation on this somewhere? ...

Calling 'git pull' from a git post-update hook

I have a central git repo set up using gitolite. I want to set up a hook such that whenever a user pushes to the repo, it performs a pull elsewhere followed by some automated testing. So far, I only want to it perform the pull. In the hooks directory I created the following script names post-update: #!/bin/sh cd /home/git/www/epica...