Translations
Info
All page names need to be in English.
en da  de  fr  it  ja  km  nl  ru  zh

warning - Message

Important notice: This wiki is scheduled to be disabled in 2021. We are in the process of migrating content to the official documentation on docs.typo3.org. If you find information here that is missing from the official documentation, please feel free to get in contact with us on TYPO3 Slack (Channel: #t3docs-sig-wiki-migration).

Extension Development, bash scripting

From TYPO3Wiki
Jump to navigation Jump to search
Content Type: HowTo.


error - This page is a candidate for deletion

Reason: Not TYPO3 specific, unclear, outdated.

If you disagree with its deletion, please explain why at Category talk:Candidates for speedy deletion or improve the page and remove the {{delete}} tag.

This notice should remain for a minimum of 1 week after it was placed on the page. If a discussion is still ongoing, it should remain until a consensus is reached or a decision has been made about the removal, after which the page will either be deleted or this notice removed.

Remember to check what links here and the the page history before deleting.

How does one pass a command-line parameter to a shell script?

The command line parameters are referenced as $1, $2, etc

Mirroring

Question:
What should this do? For security reasons it should not be possible to access an extension this way https://domain/typo3/ext/$file. Please explain what this should do or remove it. - Sypets 2020-04-18
Please remove "{{Question}}" when the problem is solved. See all questions.

If you need to mirror an extension from another server you can write a little shell-script:

 #!/bin/bash

 find extension/ > mirror
 exec 3<mirror
 
 cd folder
 
 while read file <&3
 do
 
  target=http://www.foobar.de/typo3conf/ext/
  wget $target$file
  
 done

Description: With exec 3<mirror you open a new Linux-File-Descriptor. There are unlimited Linux-File-Descriptors. Just don't use 0,1,2 because they are reserved for Linux. In the while-loop there is the condition read file from that descriptor, while file is just a variable which stores each line of mirror.

1) Here is an "one-liner" which does the same thing:

 find extension/ | sed -r -e 's/(.*?)/http:\/\/www.foobar.de\/typo3conf\/ext\/\1/g' | wget -vv -i -

Of course you can replace the lines:

   target=http://www.foobar.de/typo3conf/ext/
   wget $target$file

with

  target=destination
  mv $file $target

or

  target=folder
  cp $file $target"/"$file


or

  target=`echo $file | sed -r -e 's/needle/replace/g'
  cp $file $target

Search and Replace

If you want to search and replace all files in a directory and replace only the first occurrence:

 find /tmp | xargs perl -pi -e 's/needle/replace/g'

Without perl, it is a little more complicated:

 #!/bin/bash

 find extension/ > mirror
 exec 3<mirror

 while read file <&3
 do
  replace=`more $file | sed -r -e 's/needle/replace/g'` 
  cat $replace > $file
 done


If you already know the filename you can do this:

  
 more foobar | sed -r -e 's/needle/replace/g' > foobar

Note

Don't you use awk for search and replace!

Again without sed, it is a bit more complicated:

 more foobar | php -R 'echo preg_replace("/needle/","replace",$argn)."\r\n";' > foobar

Of course you can use perl:

 more foobar | xargs perl -pi -e 's/needle/replace/g'


Here is an example taken from my router to show you some other technique how to load a file:

#!/bin/sh

INTERVAL=120

while sleep $INTERVAL
do

  // Replace "file" with the file name that has the list of IPs
 iplist=/foobar/whitelist
 upcount=0
 downhosts=""

 for i in $(cat ${iplist})
 do
        ping -c 1 $i > /dev/null 2>&1

        if [[ $? -eq 0 ]]
        then
                let upcount+=1
        else
                downhosts="${downhosts} ${i}"
        fi
 done

 if [ $upcount -eq 0 ]
 then
      echo "The following host are down: ${downhosts}"
 else
      echo "ping: ${upcount} hosts are up"
 fi

done


--Chibox 05:41, 28 May 2008 (CEST)