shell-scripting

Why does sh/bash set command line parameter values when trying to set environment variable?

A question on basics : While tuning environment variables for a program launched from a script, I ended up with somewhat strange behaviour with sh (which seems to be actually linked to bash) : variable setting seems to mess up with command-line parameters. Could somebody explain why does this happen? A simple script: #! /bin/sh # Mes...

Inlining the LaTeX \input Command

I'm looking a program to recursively inline all \input{} commands in a LaTeX file. By "recursively", I mean doing the inlining iteratively until no \input{} command remains in the final LaTeX file. I've already come across the flatten package. But, for some reason, my TeXLive distribution doesn't install it. When I execute the command s...

How do I determine if a web page exists with shell scripting?

I am trying to make a program that can convert a series of manga scans into one pdf file, and I don't want to have to attempt to download the picture to determine if I have the right url. Is there a shell scripting command that I can use to just check if a web page exists? ...

What does the line '!/bin/sh -e' do?

In the beginning of a file on my server (linux), which is located in the /etc/init.d/ folder I have this line: !/bin/sh -e What does it mean, because every time I execute the rest of the script it works fine except for an error which shows: !/bin/sh not found Any ideas? ...

shell script filter du and find by a string inside a file in a subfolder

I have the following command that I run on cygwin: find /cygdrive/d/tmp/* -maxdepth 0 -mtime -150 -type d | xargs du --max-depth=0 > foldersizesreport.csv I intended to do the following with this command: for each folder under /d/tmp/ that was modified in last 150 days, check its total size including files within it and ...

how to find whether a script run as a nohup finished or not?

I tried running a script using nohup like, nohup script.sh & When I tried ps -ef | grep "script.sh" I couldn't find it there except for the grep which is being run with that string as a parameter. Am I doing it right?. Does this mean that the process has indeed finished execution? Thanks. ...

grep a specific word and sum it

I want to grep an environment variable env | grep ABC_IJK[1,2] currenlty defined variables are like this ABC_IJK1=123 ABC_IJK1_XYZ=sn123:345 ABC_IJK2=999 ABC_IJK2_XYZ=sn321:999 I only want to get only this ABC_IJK1=123 ABC_IJK2=999 get number of connections sum them(not 123 + 999) and save in N1 (this one has 2 connection) ...

untar filename.tr.gz to directory "filename"

I would like to untar an archive e.g. "tar123.tar.gz" to directory /myunzip/tar123/" using a shell command. tar -xf tar123.tar.gz will decompress the files but in the same directory as where I'm working in. If the filename would be "tar233.tar.gz" I want it to be decompressed to /myunzip/tar233.tar.gz" so destination directory would b...

Can we write a script to do something when a dialup connection is made to my computer?

This is the situation, I have configured a dial up server and i want to play a sound or pop up message when a daipup connection is made to my computer from a specific location. and it could be done with configuration file or some script to run some exe.please give me some ideas ...

script to delete all /n number of lines starting from a word except last line

how to delete all lines below a word except last line in a file. suppose i have a file which contains | 02/04/2010 07:24:20 | 20-24 | 26 | 13 | 2.60 | | 02/04/2010 07:24:25 | 25-29 | 6 | 3 | 0.60 | +---------------------+-------+------------+----------+-------------+ 02-04-2010-07:24 --- ER...

AWK scripting :How to remove Field separator using awk

Need the following output ONGC044 ONGC043 ONGC042 ONGC041 ONGC046 ONGC047 from this input Medium Label Medium ID Free Blocks =============================================================================== [ONGC044] ECCPRDDB_FS_43 ac100076:4aed9b39:44f0:0001 195311616 [ONG...

Shell script to count files, then remove oldest files

I am new to shell scripting, so I need some help here. I have a directory that fills up with backups. If I have more than 10 backup files, I would like to remove the oldest files, so that the 10 newest backup files are the only ones that are left. So far, I know how to count the files, which seems easy enough, but how do I then remove...

bitwise XOR a string in Bash

Hi. I am trying to accomplish a work in Bash scripting. I have a string which i want to XOR with my key. #!/bin/sh PATH=/bin:/usr/bin:/sbin:/usr/sbin export PATH teststring="abcdefghijklmnopqr" Now how do i XOR the value of teststring and store it in a variable using bash? Any help will be appreciated. Basically i am trying to dup...

Run FFmpeg from Shell Script

Hello all, I have found a useful shell script that shows all files in a directory recursively. Where it prints the file name echo "$i"; #Display File name. I would instead like to run an ffmpeg command on non MP3 files, how can I do this? I have very limited knowledge of shell scripts so I appreciate if I was spoon fed! :) //if file ...

How to run command in the background and notify me via email when done

Hello all, I have the following command which will take ages to run (couple of hours). I would like to make it a background process and for it to send me an email when its done. For the cherry on the top, any errors it encountered should write to a text file when an error has occurred? find . -type f -name "*.rm" -exec ./rm2mp3.sh \...

How to export shell variable within perl script

I have a shell script, with a list of shell variables, which is executed before entering a programming environment. I want to use a perl script to enter the programming environment: system("environment_defaults.sh"); system("obe"); but I when I enter the environment the variables are not set. ...

How to line up columns using paste(1)? or how to make an aligned table merging lines in the shell?

Hi, I want to merge lines such that the merged lines are aligned on the same boundary. UNIX paste(1) does this nicely when lines all meet at the same tab boundary, but when lines differ in size (in the file that lines are being merged into), the text comes out awkward. Example of paste(1) that has the desired effect: $ echo -e "a\nb\n...

Shell Scripting: Generating output file name in script and then writing to it

Hello, I have a shell script where a user passes different sizes as command line arguments. For each of those sizes, I want to perform some task, then save the output of that task into a .txt file with the size in the name. How can I take the command line passed and make that part of a stringname for the output file? I save the outpu...

caching problem

I wrote one script which is running on the linux machine.It fetches data from one url and displays the content on a page. The problem I am facing is some time if I refresh the page 4-5 times it displays the old content and not the latest one. The problem could be because of caching proxy which is still caching old content. Please tell m...

Help with basic shell script. /bin/sh: source: not found

My cron : 45 10 * * * source /home/ThinkCode/Test/hello.sh hello.sh : #!/bin/bash echo "helloworld" The error it emails me : /bin/sh: source: not found What am I doing wrong? It is configuration/environment specific, so Googling didn't help much! Thanks.. ...