Search Results

Search found 4958 results on 199 pages for 'shell'.

Page 19/199 | < Previous Page | 15 16 17 18 19 20 21 22 23 24 25 26  | Next Page >

  • global scope of variable

    - by shantanuo
    The following shell scrip will check the disk space and change the variable "diskfull" to 1 if the usage is more than 10% The last echo always shows 0 I tried the global diskfull=1 in the if clause but it did not work. How do I change the variable to 1 if the disk consumed is more than 10% #!/bin/sh diskfull=0 ALERT=10 df -HP | grep -vE '^Filesystem|tmpfs|cdrom' | awk '{ print $5 " " $1 }' | while read output; do #echo $output usep=$(echo $output | awk '{ print $1}' | cut -d'%' -f1 ) partition=$(echo $output | awk '{ print $2 }' ) if [ $usep -ge $ALERT ]; then diskfull=1 exit fi done echo $diskfull

    Read the article

  • What's the best way to check that environment variables are set in Unix shellscript

    - by AndrewR
    I've got a few Unix shell scripts where I need to check that certain environment variables are set before I start doing stuff, so I do this sort of thing: if [ -z "$STATE" ]; then echo "Need to set STATE" exit 1 fi if [ -z "$DEST" ]; then echo "Need to set DEST" exit 1 fi which is a lot of typing. Is there a more elegant idiom for checking that a set of environment variables is set? EDIT: I should mention that these variables have no meaningful default value - the script should error out if any are unset.

    Read the article

  • Is there a bash shortcut for traversing similar directory structures?

    - by Steve Weet
    The Korn shell used to have a very useful option to cd for traversing similar directory structures e.g. given the following directorys /home/sweet/dev/projects/trunk/projecta/app/models /home/andy/dev/projects/trunk/projecta/app/models Then if you were in the /home/sweet.... directory then you could change to the equivalent directory in andy's structure by typing cd sweet andy So if ksh saw 2 arguments then it would scan the current directory path for the first value, replace it with the second and cd there. Is anyone aware of similar functionality in bash. EDIT 1 Following on from Michal's excellent answer I have now created the following bash function called scd (For Sideways cd) function scd { cd "${PWD/$1/$2}" } EDIT 2 Thanks to @digitalross I can now reproduce the ksh functionality exactly with the code from below (With the addition of a pwd to tell you where you have changed to) cd () { if [ "x$2" != x ]; then builtin cd ${PWD/$1/$2} pwd else builtin cd "$@" fi }

    Read the article

  • Trying to test space in filesystem on Unix

    - by Buzkie
    I need to check if I Filesystem exists, and if it does exist there is 300 MB of space in it. What I have so far: if [ "$(df -m /opt/IBM | grep -vE '^Filesystem' | awk '{print ($3)}')" < "300" ] then echo "not enough space in the target filesystem" exit 1 fi This throws an error. I don't really know what I'm doing in shell. My highest priority is AIX but I'm trying to get it to work for HP and Sun too. Please help. -Alex

    Read the article

  • Editing Multiple files in vi with Wildcards

    - by Alan Storm
    When using the programmers text editor vi, I'll often using a wildcard search to be lazy about the file I want to edit vi ThisIsAReallLongFi*.txt When this matches a single file it works great. However, if it matches multiple files vi does something weird. First, it opens the first file for editing Second, when I :wq out of the file, I get a message the bottom of the terminal that looks like this E173: 4 more files to edit Hit ENTER or type command to continue When I hit enter, it returns me to edit mode in the file I was just in. The behavior I'd expect here would be that vi would move on to the next file to edit. So, What's the logic behind vi's behavior here Is there a way to move on and edit the next file that's been matched? And yes, I know about tab completion, this question is based on curiosity and wanting to understand the shell better.

    Read the article

  • sorting group of lines

    - by benjamin button
    I have a text file like below iv_destination_code_10 TAP310_mapping_RATERUSG_iv_destination_code_10 RATERUSG.iv_destination_code_10 = WORK.maf_feature_info[53,6] iv_destination_code_2 TAP310_mapping_RATERUSG_iv_destination_code_2 RATERUSG.iv_destination_code_2 = WORK.maf_feature_info[1,6] iv_destination_code_3 TAP310_mapping_RATERUSG_iv_destination_code_3 RATERUSG.iv_destination_code_3 = WORK.maf_feature_info[7,6] iv_destination_code_4 TAP310_mapping_RATERUSG_iv_destination_code_4 RATERUSG.iv_destination_code_4 = WORK.maf_feature_info[13,6] iv_destination_code_5 TAP310_mapping_RATERUSG_iv_destination_code_5 RATERUSG.iv_destination_code_5 = WORK.maf_feature_info[19,6] iv_destination_code_6 TAP310_mapping_RATERUSG_iv_destination_code_6 RATERUSG.iv_destination_code_6 = WORK.maf_feature_info[29,6] iv_destination_code_7 TAP310_mapping_RATERUSG_iv_destination_code_7 RATERUSG.iv_destination_code_7 = WORK.maf_feature_info[35,6] iv_destination_code_8 TAP310_mapping_RATERUSG_iv_destination_code_8 RATERUSG.iv_destination_code_8 = WORK.maf_feature_info[41,6] iv_destination_code_9 TAP310_mapping_RATERUSG_iv_destination_code_9 RATERUSG.iv_destination_code_9 = WORK.maf_feature_info[47,6] combination of three lines form a unit: iv_destination_code_9 TAP310_mapping_RATERUSG_iv_destination_code_9 RATERUSG.iv_destination_code_9 = WORK.maf_feature_info[47,6] is one unit. iv_destination_code_9 9 indicates the number by which i have to sort 10 9 8.... i need a shell script/awk which will sort the units in a descending order. how is it possible?

    Read the article

  • Random password variable disappears

    - by snaken
    Hi, I'm using the following to generate a random password in a shell script: DBPASS=</dev/urandom tr -dc A-Za-z0-9| (head -c $1 > /dev/null 2>&1 || head -c 8) When i run this in a file on its own like this: #!/bin/sh DBPASS=</dev/urandom tr -dc A-Za-z0-9| (head -c $1 > /dev/null 2>&1 || head -c 8) echo $DBPASS A password is echoed. When i incorporate it into a larger script though the variable never seems to get created for some reason, so for example this doesn't work: DBPASS=</dev/urandom tr -dc A-Za-z0-9| (head -c $1 > /dev/null 2>&1 || head -c 8) sed -i s/oldpass/$DBPASS/ mysql_connect.php If i manually set the variable though everything is fine.. can anyone see why?

    Read the article

  • Whats the difference between running a shell script as ./script.sh and sh script.sh

    - by Ritesh M Nayak
    I have a script that looks like this #!/bin/bash function something() { echo "hello world!!" } something | tee logfile I have set the execute permission on this file and when I try running the file like this $./script.sh it runs perfectly fine, but when I run it on the command line like this $sh script.sh It throws up an error. Why does this happen and what are the ways in which I can fix this.

    Read the article

  • prepend to a file one liner shell?

    - by elmarco
    This is probably a complex solution. I am looking for a simple operator like "", but for prepending. I am afraid it does not exist. I'll have to do something like mv $F tmp cat header tmp $F Anything smarter? (I am not fond of tmp files)

    Read the article

  • Running shell scripts with sudo through my Rails app

    - by nfm
    In my Rails app, I have some functionality that interfaces with the server's OS. I've written a bash script, put it in my lib/ subdirectory, and can run it from my controller. However, some functionality of the script requires superuser privileges. What is the most sane way to run this script securely? It is being passed arguments from a web form, but should only be able to be called by authenticated (and trusted) users.

    Read the article

  • Bash Shell Script: Nested Select Statements

    - by CCG121
    I have A Script that has a Select statement to go to multiple sub select statements however once there I can not seem to figure out how to get it to go back to the main script. also if possible i would like it to re-list the options #!/bin/bash PS3='Option = ' MAINOPTIONS="Apache Postfix Dovecot All Quit" APACHEOPTIONS="Restart Start Stop Status" POSTFIXOPTIONS="Restart Start Stop Status" DOVECOTOPTIONS="Restart Start Stop Status" select opt in $MAINOPTIONS; do if [ "$opt" = "Quit" ]; then echo Now Exiting exit elif [ "$opt" = "Apache" ]; then select opt in $APACHEOPTIONS; do if [ "$opt" = "Restart" ]; then sudo /etc/init.d/apache2 restart elif [ "$opt" = "Start" ]; then sudo /etc/init.d/apache2 start elif [ "$opt" = "Stop" ]; then sudo /etc/init.d/apache2 stop elif [ "$opt" = "Status" ]; then sudo /etc/init.d/apache2 status fi done elif [ "$opt" = "Postfix" ]; then select opt in $POSTFIXOPTIONS; do if [ "$opt" = "Restart" ]; then sudo /etc/init.d/postfix restart elif [ "$opt" = "Start" ]; then sudo /etc/init.d/postfix start elif [ "$opt" = "Stop" ]; then sudo /etc/init.d/postfix stop elif [ "$opt" = "Status" ]; then sudo /etc/init.d/postfix status fi done elif [ "$opt" = "Dovecot" ]; then select opt in $DOVECOTOPTIONS; do if [ "$opt" = "Restart" ]; then sudo /etc/init.d/dovecot restart elif [ "$opt" = "Start" ]; then sudo /etc/init.d/dovecot start elif [ "$opt" = "Stop" ]; then sudo /etc/init.d/dovecot stop elif [ "$opt" = "Status" ]; then sudo /etc/init.d/dovecot status fi done elif [ "$opt" = "All" ]; then sudo /etc/init.d/apache2 restart sudo /etc/init.d/postfix restart sudo /etc/init.d/dovecot restart fi done

    Read the article

  • Unfold vCard lines in shell

    - by l0b0
    vCard lines can be folded by inserting "\r\n " (that's a space at the start of the new line), but I'm struggling to unfold them with the line-oriented GNU tools (sed, cut). Any ideas? Effectively, from the string foo bar baz ban bay bal it must return foobar baz banbaybal

    Read the article

  • Sorting shell items like windows explorer

    - by Roy M Klever
    Hi, I am making a bread crumb bar in Delphi and having some problems regarding sorting the dropdown of the bread crumbs. Strangely enough, even Vista is not consequent when showing these items. I have tried many ways to figure out what is system folders, what is zip files and what is normal folders. It seems like an easy task but so far I have not found any good way of doing it. One way is to use TypeDisplayName from TSHFileinfo but these are localized names so I can not be sure they will be in correct order in every language. Here is the code I use to fill the menu: bool:= IsDesktop(SelectedPIDL); if bool then OleCheck(SHGetDesktopFolder(CurFolder)) else OleCheck(DesktopShellFolder.BindToObject(SelectedPIDL, nil, IID_IShellFolder, Pointer(CurFolder))); if CurFolder.EnumObjects(0, SHCONTF_FOLDERS, EnumIDList) = NOERROR then begin while EnumIDList.Next(1, CurPidl, Fetched) = S_OK do begin FName:= GetDisplayName(CurFolder, CurPidl, SHGDN_NORMAL); Text:= GetPIDLNameForAddressBar(CurFolder, CurPidl); if bool then Text:= PSpecialFolderItem(SpecialFolders[0]).Name + '\' + Text; if Text[Length(Text)] <> '\' then Text:= Text + '\'; NewPidl:= ConcatPIDLs(SelectedPIDL, CurPidl); SHGetFileInfo(PChar(NewPidl), 0, SFI, SizeOf(SFI), SHGFI_ATTRIBUTES or SHGFI_PIDL or SHGFI_SYSICONINDEX or SHGFI_TYPENAME); n:= SFI.dwAttributes; MenuList.Add(GetAttr(n) + FName); AddMenuItem(Text, FName, SFI.iIcon); CoTaskMemFree(CurPidl); CoTaskMemFree(NewPidl); end; end; CoTaskMemFree(SelectedPIDL); Any solution for how to get the correct sorting order? It is strange there is no way in dwAttributes of TSHFileInfo to tell if a folder is a system folder. Roy M Klever

    Read the article

  • finding the missing values in a range using any scripting language - perl, python or shell script

    - by manu
    Hi everyone I got stuck in one problem of finding the missing values in a range and the range is also variable for the successive rows. Ex. =================== inpt ==================== 673 673 673 676 676 680 2667 2667 2668 2670 2671 2674 ===================== output should be like this =================== 674 675 677 678 679 2669 2672 2673 ======================== This is just one part and the row values can be more also If there is any clarification plz let me know. thanx in advance manu

    Read the article

  • Delphi Shell IExtractIcon usage and result

    - by Roy M Klever
    What I do: Try to extract thumbnail using IExtractImage if that fail I try to extract icons using IExtractIcon, to get maximum iconsize, but IExtractIcon gives strange results. Problem is I tried to use a methode that extracts icons from an imagelist but if there is no large icon (256x256) it will render the smaller icon at the topleft position of the icon and that does not look good. That is why I am trying to use the IExtractIcon instead. But icons that show up as 256x256 icons in my imagelist extraction methode reports icon sizes as 33 large and 16 small. So how do I check if a large (256x256) icon exists? If you need more info I can provide som sample code. if PThumb.Image = nil then begin OleCheck(ShellFolder.ParseDisplayName(0, nil, StringToOleStr(PThumb.Name), Eaten, PIDL, Atribute)); ShellFolder.GetUIObjectOf(0, 1, PIDL, IExtractIcon, nil, XtractIcon); CoTaskMemFree(PIDL); bool:= False; if Assigned(XtractIcon) then begin GetLocationRes := XtractIcon.GetIconLocation(GIL_FORSHELL, @Buf, sizeof(Buf), IIdx, IFlags); if (GetLocationRes = NOERROR) or (GetLocationRes = E_PENDING) then begin Bmp := TBitmap.Create; try OleCheck(XtractIcon.Extract(@Buf, IIdx, LIcon, SIcon, 32 + (16 shl 16))); Done:= False; Roy M Klever

    Read the article

  • grep 5 seconds of input from the serial port inside a shell-script

    - by pica
    I've got a device that I'm operating next to my PC and as it runs it's spitting log lines out it's serial port. I have this wired to my PC and I can see the log lines fine if I'm using either minicom or something like: ttylog -b 115200 -d /dev/ttyS0 I want to write 5 seconds of the device serial output to a temp file (or assign it to a variable) and then later grep that file for keywords that will let me know how the device is operating. I've already tried redirecting the output to a file while running the command in the background, and then sleeping 5 seconds and killing the process, but the log lines never get written to my temp file. Example: touch tempFile ttylog -b 115200 -d /dev/ttyS0 >> tempFile & serialPID=$! sleep 5 #kill ${serialPID} #does not work, gets wrong PID killall ttylog cat tempFile The file gets created but never filled with any data. I can also replace the ttylog line with: ttylog -b 115200 -d /dev/ttyS0 |tee -a tempFile & In neither case do I ever see any log lines logged to stdout or the log file unless I have multiple versions of ttylog running by mistake (see commented out line, D'oh). I have no idea what's going on here. It seems to be a failure of redirection within my script. Am I on the right track? Is there a better way to sample 5 seconds of the serial port?

    Read the article

  • Shell script argument parsing

    - by Peter Coulton
    There are a number of questions about this sort of thing but lets imagine we are targeting a generic Linux system with both getopt and getopts installed (not that we'll use either, but they seem popular) How do I parse both long (--example | --example simple-option) and short argruments (-e | -esimple-example | -e simple-example)

    Read the article

  • GnuPG Shell Script - Refuses to read password

    - by OopsForgotMyOtherUserName
    The script below used to work on Mac OS X, but, since moving it to Ubuntu, it doesn't seem to read from the password file at all. Even when I run it from the command line, no matter what I do, I get a popup prompt asking me for the password. As this will run via cron, I don't want this to happen... I want it to read the password from the file with no prompt. To note, I did try using passphrase-fd and passphrase-file, neither of which worked... #!/bin/sh p=$(<pass.txt) set -- $p pass_phrase=$1 destination="/var/www/decrypted" cd /var/sl_bin/ for FILE in *.pgp; do FILENAME=${FILE%.pgp} gpg --passphrase "$pass_phrase" --output "$destination/$FILENAME" --decrypt "$FILE" rm -f $FILE done

    Read the article

  • Difference between piping a file to sh and calling a shell file

    - by Peter Coulton
    This is what was trying to do: $ wget -qO- www.example.com/script.sh | sh which quietly downloads the script and prints it to stdout which is then piped to sh. This unfortunately doesn't quite work, failing to wait for user input a various points, aswell as a few syntax errors. This is what actually works: $ wget -qOscript www.example.com/script.sh && chmod +x ./script && ./script But what's the difference? I'm thinking maybe piping the file doesn't execute the file, but rather executes each line individually, but I'm new to this kind of thing so I don't know.

    Read the article

  • FTP to SFTP in shell scripting

    - by Kimi
    This script is to connect to different servers and copy a file from a loaction defined. It is mandatory to use sftp and not ftp. #!/usr/bin/ksh -xvf Detail="jyotibo|snv4915|/tlmusr1/tlm/rt/jyotibo/JyotiBo/ jyotibo|snv4915|/tlmusr1/tlm/rt/jyotibo/JyotiBo/" password=Unix11! c_filename=import.log localpath1=`pwd` for i in $Detail do echo $i UserName=`echo $i | cut -d'|' -f1` echo $UserName remotehost=`echo $i | cut -d'|' -f2` echo $remotehost remote_path=`echo $i | cut -d'|' -f3` echo $remote_path { echo "open $remotehost user $UserName $password lcd $localpath1 cd $remote_path bi prompt mget $c_filename prompt " } |ftp -i -n -v 2>&1 done I want to do the similar thing using sftp instead of ftp.

    Read the article

  • crone tab shell script do not save output

    - by Anas
    i use cron tab with command wget http://www.mydomain.com/page.php to run one of my pages in server. It works, but problem is output is sved with names page.php, page.php1, page.php2, page.php3 etc. Can i run the page using wget without sving output

    Read the article

  • Selecting Update queries alone from list of files using shell script

    - by Harish
    I am trying to get Update queries from a list of files using this script.I need to take lines containing "Update" alone and not "Updated" or "UpdateSQL"As we know all update queries contain set I am using that as well.But I need to remove cases like Updated and UpdatedSQL can anyone help? nawk -v file="$TEST" 'BEGIN{RS=";"} /[Uu][Pp][Dd][Aa][Tt][Ee] .*[sS][eE][tT]/{ gsub(/.*UPDATE/,"UPDATE");gsub(/.*Update/,"Update");gsub(/.*update/,"update");gsub(/\n+/,"");print file,"#",$0;} ' "$TEST" >> $OUT

    Read the article

< Previous Page | 15 16 17 18 19 20 21 22 23 24 25 26  | Next Page >