w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Mac OSX LaunchDaemon on Startup, Shell Script with SSH
What errors are you seeing? I would expect that you may have a PATH problem here. Where is mysqldump? If it's in /usr/local/bin, then you probably want to make that explicit, or set the default path in /etc/launchd.conf.

Categories : Osx

Issue on reading a CSV file into FME through a startup python script
Did you have a look at the file that your python script writes to your disk? This might at least show you why there is a difference. I don't think this has anything to do with FME. In FME2013 you can directly use the reader to access a web-based source dataset. This works for any file-based format and even zipped data. So you don't need to use the python-script to download the file before.

Categories : Csv

Fallback on Local js file If file is missing from remote path
Something like this might work: <script src="http://tab-slide-out.googlecode.com/files/jquery.tabSlideOut.v1.3.js"></script> <script> if(!jQuery().tabSlideOut) document.write('<script src="js/jquery.tabSlideOut.v1.3.js"></script>'); </script>

Categories : Jquery

Translating shell script into Windows command shell script (batch)
for /L makes a count-controlled loop in batch. mkdir remains mkdir. @echo off for /L %%y in (1,1,9) do mkdir week_0%%y mkdir week_10

Categories : Shell

how to pass variable from python to shell script when shell script is getting called inside python script
You can: Step through the list, and then call mail.sh once for each file. This is the most reliable way. Convert the items in the list to a space delimited string, and then pass it in to mail.sh (assuming mail.sh is setup correctly, it should accept multiple arguments). What you cannot do is pass ['a.txt','b.txt','c.txt'] wholesale to the script.

Categories : Python

How to make a shell script that opens a file and adds lines at the end of the file and then saves?
To answer the question in the title, $ echo "root soft nofile 65536" >> /etc/security/limits.conf will add the line root soft nofile 65536 at the end of the file. To reboot, in many linux systems, you just have to do : $ reboot And to test a value , you could do something like : if [ "`ulimit -n`" -lt "65536" ]; then # do stuff fi So finally, your script would look like : #!/bin/sh if [ "`ulimit -n`" -lt "65536" ]; then file='/etc/security/limits.conf' { echo "root soft nofile 65536" echo "root hard nofile 65536" echo "soft nofile 65536" echo "soft nofile 65536" } >> $file reboot fi

Categories : Shell

Using Shell script and sed - Find and replace a word in file and rename file
I guess you are making it complex: why not make it simple with two simple satements. Its up to you how you use the below statements for your purpose: perl -pi -e 's/wordtofind/wordtoreplace' your_file #for replacing the word in the file mv your_file wordtoreplace #for renaming the file

Categories : Shell

shell script to create backup file when creating new file in particular directory
Can you explain why you want to do? Tools like VIM can create a backup copy of a file you're working on automatically. Other tools like Dropbox (which works on Linux, Windows, and Mac) can version files, so it backs up all the copies of the file for the last 30 days. You could do something by creating aliases to the tools you use for creating these file. You edit a file with the tools you tend to use, and the alias could create a copy before invoking a tool. Otherwise, your choice is to use crontab to occasionally make backups. Addendum let me explain suppose i have directory /home/pavan now i create the file myfile.txt in that directory , immediately now i should automatically generate myfileCopy.txt file in the same folder paven There's no easy user tool that could do that.

Categories : Linux

how to fetch details from a file and store in a temporary file in shell script?
You can try this : x=($(grep -Po "(?<=DB_IP=)(.+)(?=,)|(?<=DB_NAME=)(.+)" config.txt)) y=($(grep -Eo "[a-zA-Z_]+=" details.txt)) echo $y$x > temp.txt echo ${y[1]}${x[1]} >> temp.txt Assuming that the order of DB_IP and DB_NAME is always same in both files.

Categories : Shell

Create output file names based on input file name with autonumbers shell script linux
VAR="INPUTFILENAME" # One solution this does not use the VAR: touch INPUTFILENAME{1,2,3,4,5,6,7,8,9,10} # Another for i in `seq 1 20` ; do touch "${VAR}${i}" done And there are several other ways.

Categories : Linux

How to convert xml file in to a property file using unix shell script
this may help? <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="//person"> "<xsl:value-of select="name"/>" = "<xsl:value-of select="family-name"/>" </xsl:template> </xsl:stylesheet> save it as x.xslt and do xsltproc x.xslt file.xml

Categories : Xml

Shell script: copying columns by header in a csv file to another csv file
Just figure out the name associated with each column and use that mapping to manipulate the columns. If you're trying to do this in awk, you can use associative arrays to store the column names and the rows those correspond to. If you're using ksh93 or bash, you can use associative arrays to store the column names and the rows those correspond to. If you're using perl or python or ruby or ... you can... Or push the columns into an array to map the numbers to column numbers. Either way, then you have a list of column headers, which can further be manipulated however you need to.

Categories : Shell

Getting file through FTP using shell script
'ftp' is so 80s! Why don't you move up the foodchain a little? wget --user="${FTP_USER}" --password="${FTP_PASS}" "${FTP_SITE}/dir/files" wget supports the FTP protocol and can continue interrupted downloads, can exclude files, can do recursive retrieval and just about anything.

Categories : Unix

shell script : how to replace file name
Created using bash on a mac, so it might work with whatever shell you are using... string="/home/guest/test" echo $string | sed 's//([^/]{0,})$//.1.log/' Using simple shell string replacement wasn't going to work since I know of no way you can target the last occurrence of the / sign as the only replacement. Update: Actually I came to think of a alternative way if you know that it is always "/two/directories/in" string="/home/guest/test" firstpartofstring=$(echo $string | cut -d/ -f1-3) lastpartofstring=$(echo $string | cut -d/ -f4) echo ${firstpartofstring}/.${lastpartofstring}.log

Categories : Shell

shell script to add header to a file
You can use awk like this: awk 'NR==FNR && !h {print;h=1;} NR!=FNR{print}' headerFile mainFile > tmpFile mv tmpFile mainFile Using vim/vi: vim +'0r headerFile|wq' mainFile 2>/dev/null Using GNU sed: sed -i.bak -e '2{x;G};1{h;rheaderFile' -e 'd}' mainFile Using non-GNU sed: HDR=$(head -1 headerFile) && sed -i.bak "1s/^/$HDR/" mainFile

Categories : Shell

How to create file validation shell script?
Keeping it simple, and assuming that by "shell" you mean a Unix shell: ls -1 path/to/directory | sort > list1.txt sort file_with_filenames.txt > list2.txt diff list1.txt list2.txt You can probably tweak this into a smart loop or one-liner, but for a one-shot problem this should suffice. Upside is that you don't have to worry about spaces in filenames, which can make looping solutions rather tricky. You can use the return code from diff to break if there are any differences. Since you didn't state any specific requirements, I didn't bother with things like creating the list files in /tmp making this re-entrant (e.g. by including PID in the temporary filenames) cleaning up the temporary files afterwards do sanity checks (existence of directory / filelist etc.) "Production" qua

Categories : File

xcrun file shell script code in Mac OSX 10.7.5
To install the version of xcrun that you want you should install the corresponding version of Xcode. Go to Xcode->Preferences->Downloads->Components. Then click the button to install the Command Line Tools.

Categories : IOS

shell script: inserting a new line to a file using sed
The second example on the cited link is a solution for you < a.txt sed "/ABC$/a \ #define DEF " will produce from the a.txt #define ABC the output #define ABC #define DEF Or the 5th example from the above link < a.txt sed "/ABC$/s/$/\ #define DEF/" so, READ!

Categories : Shell

CSV file date processing in shell script
I did it in basic shell script with nanoseconds: while read line do d1=$(echo $line | cut -d, -f1) d2=$(echo $line | cut -d, -f2) ds1=$(date -d"$d1" "+%s.%N") ds2=$(date -d"$d2" "+%s.%N") diff=$(echo "$ds2 - $ds1" | bc) printf "$ds2 - $ds1 = %.3f " $diff done < file Test $ while read line; do d1=$(echo $line | cut -d, -f1); d2=$(echo $line | cut -d, -f2); ds1=$(date -d"$d1" "+%s.%N"); ds2=$(date -d"$d2" "+%s.%N"); diff=$(echo "$ds2 - $ds1" | bc); printf "$ds2 - $ds1 = %.3f " $diff; done < file 1373524748.748000000 - 1373524748.748000000 = 0.000 1373524748.826000000 - 1373524748.826000000 = 0.000 1373524748.860000000 - 1373524748.860000000 = 0.000 1373524748.919000000 - 1373524748.919000000 = 0.000 1373524748.941000000 - 1373524748.941000000 = 0.000 1373524749.39

Categories : File

Shell command works in shell but not in shell script
You are using single quotes in this command: filelist=$(grep '$incstring' -rl --include=*.{h,cpp} pathToFiles) Single quotes inhibit variable expansion. That is, you're looking for the literal string $incstring rather than the contents of that variable. This command, as shown here, would not have worked on the command line either. From the bash(1) man page: Enclosing characters in single quotes preserves the literal value of each character within the quotes. A single quote may not occur between single quotes, even when preceded by a backslash. Replace the single quotes with double quotes: filelist=$(grep "$incstring" -rl --include=*.{h,cpp} pathToFiles)

Categories : Shell

How to sort random strings in a file via shell script
Whole idea is to grep every «string» and then collapse it to single line via tr. $> grep -P -o "[0-9a-z-]+" file | sort --unique | tr ' ' ' ' ticket-125788 ticket-125948 ticket-126824 ticket-126914 ticket-126957 ticket-126961 ticket-127012 ticket-127022 ticket-127024 ticket-127030 ticket-127035 ticket-127220 ticket-127262

Categories : Bash

file region locking using bash shell script
As you use flock (1) (which is a C program, see http://util-linux.sourcearchive.com/documentation/2.17/flock_8c-source.html) to utilize flock (2), you would need a similar command that utilizes fcntl. If such a command doesn't exist yet, one would have to write it.

Categories : Linux

Reading data from properties file in shell script
I'm certain that the file /opt/oracle/scripts/user.properties contains CR+LF line endings. (Running the file command for the properties file would say ... with CRLF line terminators). Changing those to LF using dos2unix or any other utility should make it work. Moreover, instead of saying: conn=$username$password$service_name you could say: conn="${username}${password}${service_name}"

Categories : Linux

Directory or File contain space error in Shell Script
Classic; don't use for .. in, use find "$INDIR" -type f | while read file; do echo "Encrypting $file" "$PROJECT_DIR/crypt" -e -k $ENC_KEY -i "$file" -o "$OUTDIR/`basename "$(dirname ${file})"`/`basename "$file"`" done

Categories : Osx

How to zip a file in windows shell without vb script and with Window default zip only
Yes and no. There is no built in way to do this inside windows. You can use a external application like vbscript, a exe file like 7zip, rar, lots of resources can do this. Since windows is application poor when it comes to command lines is not really surprising. But no you do not need the VB Script for anything. Just not so easy out of the box. Maybe makecab could do it for you? As a general rule you have a hard constraint in your question. A single BAT file which in general can not do almost anything without the support of hundreds of preinstalled or commonly installed other applications. Could you specify a the constraints a bit better. Tel WHY you need this particular constraint? And what does it mean as even most of the bat command you use require more than one file.

Categories : Shell

Using a file input as stdin for a shell script does not work
What do you need the <&1 for? Remove it, and it works. while read CMD; do ./test.sh < input.txt BEGIN get_start END get_stop END get_uknown_command END

Categories : Linux

how to find/fetch number in a file using shell script
A=$(egrep -o '[0-9]+' my_file | egrep -c '^1') The first egrep finds all the numbers and outputs them. The second egrep uses the -c option to output the count of matches, and the regexp matches lines that begin with 1.

Categories : Linux

shell script taking last empty line of a file also
while read LINE do [ -z "$LINE" ] && continue IMEI=$(echo $LINE | sed 's/ //g' | sed -e 's/[^ -~]//g') END_SERIAL=$(echo $IMEI | cut -c9- | sed 's/ //g' | sed -e 's/[^ -~]//g') echo "CRE:EQU,${IMEI}0,${END_SERIAL},${list},,${TODAY};" >> ${OUTFILE}i done < "${FILE_NAME}" If the line is empty, continue with the next iteration of the loop. Or have sed delete blank lines (containing blanks and tabs only) before feeding the file to the loop: sed '/^[ ]*$/d' "$FILE_NAME" | while read LINE do IMEI=$(echo $LINE | sed 's/ //g' | sed -e 's/[^ -~]//g') END_SERIAL=$(echo $IMEI | cut -c9- | sed 's/ //g' | sed -e 's/[^ -~]//g') echo "CRE:EQU,${IMEI}0,${END_SERIAL},${list},,${TODAY};" >> ${OUTFILE}i done

Categories : Linux

Shell script not redirecting correct output to a file
It all depends on what OS and version of the software you're using on but it probably boils down to this: many common commands are designed to work slightly differently depending on whether they're being called interactively or in a pipeline. (in this context, redirecting and piping would have the same results, as the command decide their behavior based on whether stdout is bound to a terminal) The most pervasive example would be ls: by default it lists files in column in interactive mode and one for per line in pipe mode. Check your man page for documented behavior with ps. You can emulate pipe mode while keeping output to stdout by piping to cat: ps -a | cat Another explanation, if you're under a weird enough shell, is that it has a builtin for ps, but doesn't wish to use it in cert

Categories : Shell

Using shell script to pull strings out of a config file
# with /bin/bash . <(awk '/define/ {print $2"="$4}' FS="'" foo.php) # with /bin/sh declare `awk '/define/ {print $2"="$4}' FS="'" foo.php` Result echo $DB_SERVER # localhost Example

Categories : Shell

How to get, copy and replace a non-ascii character in file with shell script?
To get the non-ascii characters in file user can use the following sed statement. sed 's/[^d32-d126]//g' <file_name> Above instruction will print the non ASCII characters in the input file to stdout. By giving -i option to sed user can remove the ASCII characters from the file. To replace the non-ascci characters with a particular character user can use the following statement. sed 's/[d32-d126]/<replacing_char>/g' <file_name>

Categories : Shell

Shell Script, finding time difference and traversing a file
Here's a solution using Python: import collections import datetime import sys login = {} # { username : logintime } state = collections.defaultdict(int) # { username : refcount } def parse_time(text): """Return timedelta since midnight given input as hh:mm:ss:fff.""" hh, mm, ss, fff = text.split(':') total_seconds = int(hh)*3600 + int(mm)*60 + int(ss) + int(fff)/1000 return datetime.timedelta(seconds=total_seconds) for line in open(sys.argv[1]): tokens = line.split() if tokens: time, user, action = tokens if action == 'Login': state[user] += 1 if state[user] == 1: logi

Categories : Shell

Unix - Shell script to find a file from any directory and move it
find / -type f -name FILENAME | xargs -I foobar echo mv foobar /tmp (remove echo to make the command actually work .. i put it there just to save yourself from accidentally moving files just to try out the command) Note that -I foobar means that in mv foobar /tmp replace the foobar string with full path of the file found. for example, try: find / -type f -name FILENAME | xargs -I foobar foobar is a cool file

Categories : Shell

Shell script: Count files, delete 'X' oldest file
Something along the lines like this might work: ls -1t /path/to/directory/ | head -n 14 | tail -n 1 in the ls command, -1 is to list just the filenames (nothing else), -t is to list them in chronological order (newest first). Piping through the head command takes just the first 14 from the output of the ls command, then tail -n 1 takes just the last from that list. This should give the the file that is 14th newest.

Categories : Linux

replacing multiple lines in shell script with only one output file
$ cat foo.input I am longer than 9 characters I am also longer than 9 characters I am not Another long line short $ while read line; do printf "$line"; (( ${#line} < 9 )) && printf " 1"; echo; done < foo.input I am longer than 9 characters I am also longer than 9 characters I am not 1 Another long line short 1

Categories : Shell

Shell script for search and copy file type with date in name
What you've attempted seems pretty different from the problem you've described. If you want to generate dates for the next n days given a start date, use a loop: start="20130801" for i in {1..7}; do date +%Y%m%d --date="+${i} days ${start}" done Upon executing the above bit, you'd get: 20130802 20130803 20130804 20130805 20130806 20130807 20130808

Categories : Shell

How to keep blank lines in the end of a file when I user cat command in shell script
You don't need cat command here, directly use awk like this: awk 'END {print NR}' a.txt Your problem is in storing the cat's output in a shell variable. Even this will give right output (though case of UUOC): cat a.txt | awk 'END {print NR}' Update: When you try to do this: a=`cat a.txt` OR else: a=$(cat a.txt) Pitfall is that the process substitution i.e. command inside reverse quote like you have or in $() strips trailing newlines. You can do this trick to get trailing newlines stored in a shell variable: a=`cat a.txt; echo ';'` a="${a%;}" Test the variable value: echo "$a" printf "%q" "$a" Then output will show newlines as well: jhasdfj sdfjalskdf $'jhasdfj sdfjalskdf '

Categories : Linux

Generate a Properties File using Shell Script and Results from a SQL Query
It is possible to to this from your command line SQL client but as STTLCU notes it might be better to get the query to output in something "standard" (like CSV) and then transform the results with a shell script. Otherwise, because a lot of the features you would use are not part of any SQL standard, they would depend on the database server and client application. Think of this step as sort of the obverse of ETL where you clean up the data you "unload" so that it is useful for some other application. For sure there's ways to build this into your query application: e.g. if you use something like perl DBI::Shell as your client (which allows you to connect to many different servers using the DBI module) you can jazz up your output in various ways. But here you'd probably be best off if coul

Categories : SQL

How to catch signals from a shell script which is executing a file which may throw it?
In part, see Exit status codes greater than — possible? The WIFSIGNALED stuff tells you that a process was signalled, but there's a problem for the shell encoding that, and it does it by encoding a signalled exit status as 128 + signal number (129 for HUP, 130 for INT, etc). To demonstrate shell and signal exit statuses: $ cat killme.sh #!/bin/bash kill ${1:-"-INT"} $$ $ ./killme.sh -HUP; echo $? Hangup: 1 129 $ ./killme.sh -TERM; echo $? Terminated: 15 143 $ ./killme.sh -QUIT; echo $? 0 $ ./killme.sh -PIPE; echo $? 141 $ ulimit -a core file size (blocks, -c) 0 ... $ This more or less justifies my '128+signum' claim (the -QUIT behaviour is unexpected, but explainable after a fashion — it normally dumps core, but didn't because ulimit has them disabled). In bash, you can g

Categories : C

Extract .tar File to Current Directory Automatically with Shell Script
You can try: -C, --directory DIR change to directory DIR and $(dirname "$x") for file directory for x in in /home/davidwright/attachments/*/*.tar do echo "extracting $x" tar -xvf "$x" -C "$(dirname "$x")" done

Categories : Bash



© Copyright 2017 w3hello.com Publishing Limited. All rights reserved.