Page 30 of 98 FirstFirst ... 2028293031324080 ... LastLast
Results 291 to 300 of 978

Thread: Inspired

  1. #291
    Join Date
    Mar 2010
    Location
    USA
    Beans
    Hidden!
    Distro
    Ubuntu Development Release

    Re: Inspired

    Here's a function prototyping script to show you what was talked about today would look like...
    Code:
    #!/bin/bash
    
    ## MAFoElffen, <mafoelffen@ubuntu.com>, 2021.08.31
    ## Paster()
    #      Function. Possible Version 4, 2021.09.08
    
    report=$HOME/system-info.txt
    startt="$(date '+%F  %T %Z (%z)')"
    
    function GetPingStatus()
    {
        # Takes arg as IP or URL. Returns psuedo boolean $return_status.
        ping -c 1 $1 > /dev/null
        pingStatus=$?
        if [ $pingStatus == 0 ]
        then 
            return_status="true"
        else 
            return_status="false"
        fi    
    }
    
    function nl() 
    {
        echo -e ""
    }
    
    function ProgressActive()
    {
        # Provides a spinner to show progress. Called once by Paster.
        declare -a spinner=("\b|" "\b/" "\b-" "\b\\" "\b-")
        
        echo -ne '         '
        while test -f "$1"
         do
             for spin in "${spinner[@]}"
             do 
                 stdbuf -oL echo -ne $spin
                 sleep 0.2
             done
        done
        stdbuf -oL echo -en '\b '
    }
    
    function PasteCurl()
    {
        return_url=$(curl -fsSL -X POST \
            --url $target \
            --output /dev/null \
            --write-out "%{url_effective}\n" \
            --data-urlencode "content@${PASTEBIN_CONTENT:-$report}" \
            --data "poster=${PASTEBIN_POSTER:-`whoami`@`hostname`}" \
            --data "syntax=${PASTEBIN_SYNTAX:-text}" \
            --data "expiration=${PASTEBIN_EXPIRATION:-week}")
        check_paste=$?
    }
    
    function PastePastebinit()
    {
        return_url=$(pastebinit \
            -a "$USER" \
            -i "$report" \
            -b "$target" \
            -t "$sname.txt")
        check_paste=$?
    }
    
    function PasteWget()
    {
        return_url=$(wget --quiet -O- --post-data=$report 'termbin.com:9999' )
        check_paste=$?
    }
    
    function PasteNc()
    {
        echo -e "This uses a program which sometimes conflicts with " 
        echo -e "Anti-Virus Programs. You should turn that off if you "
        echo -e "have installed."
        read -p "Would you like to proceed or skip? (y/N) " ans
        if [[ ${ans,} =~ ^[Yy]$ ]]
        then
            return_url=$(cat $report | nc termbin.com 9999 )
            check_paste=$?
        else
            echo -e "You skipped uplloading to Pastebin."
            check_paste=1
        fi
    }
    
    
    function CheckCurl()
    {
        [ -e /usr/bin/curl ];
        check_curl=$?
    }
    
    function CheckPasterProgs()
    {
        if [ -e /usr/bin/curl ]
        then
            paste_prog=1;
        elif [ -e /usr/bin/pastebinit ]
            paste_prog=2;
        elif [ -e /usr/bin/wget ]
            paste_prog=3;
        elif [ -e /usr/bin/nc ]
            paste_prog=4;
        else
            paste_prog=0;
            echo -e "Many utilites were not found. Something is wrong.";
        fi
    }
    
    function DoPaste()
    {
        prog_here=$1
        case $prog_here in
            1)
                PasteCurl
                ;;
            2)
                PastePastebinit
                ;;
            3)
                PasteWget
                ;;
            4)
                PasteNc
                ;;
            *)
                echo -e "Something went wrong. Error out of range."
                exit 1
        esac    
    }
    
    function Paster() 
     {
         # Provides an upload of report with a progress bar. Called once by Main().
         target="https://paste.ubuntu.com"
         linklog="$HOME/system-info-link.log"
    
         echo -e "$blueback Sensitive data is [REMOVED] from the report file $resetvid"
         CheckPasterProgs     
         ## Eval $paste_prog
         if [ $paste_prog -ne 0 ]
         then 
             read -p "Do you want to upload the report file fo '$target'? (y/N) " ans
             if [[ ${ans,} =~ ^[Yy]$ ]]
             then
                 GetPingStatus "www.ubuntu.com"
                 if [ "$return_status" == "true" ]
                 then
                     echo "Uploading '$report' to '$target'"
                     echo -e "This may take 1-2 minutes..."
                     nl
                     tput civis
                     keep_spinning=$(mktemp)
                     ProgressActive "$keep_spinning" & pid_progressactive=$!
                     DoPaste $paste_prog
                     if [ $check_paste -eq 0 ]
                     then
                        paste_done=true
                     else
                        paste_done=false
                     fi
                     rm "$keep_spinning"
                     sleep 0.5
                     tput cnorm
                     if [ $paste_done == 0 ]
                     then
                         echo -e "Uploaded Report: ${startt}:" >> "$linklog"
                         echo -e "$blueback Upload successful $resetvid"
                         nl
                         echo -e "The link to the pastebin is saved in: '$linklog'"
                         nl
                         echo -e "View at: $return_url" | tee -a "$linklog"
                         nl
                     else
                        echo -e "$redback Upload failed $resetvid"
                         echo -e "Upload the file manually: 'copy & paste' to"
                         echo -e "https://paste.ubuntu.com/"
                         nl
                     fi
                 else
                        echo -e "No connection to pastebin.ubuntu.com " | tee -a "$linklog"
                        echo -e "Please copy the file $report to a USB and post "
                        echo -e "from a computer that does have a working connection."
                        echo -e "Upload the file manually: 'copy & paste' to"
                        nl
                        echo -e "https://paste.ubuntu.com/"
                 fi
             fi
        else
            echo -e "$redback    The required package was not installed.    $resetvid"
            nl
            echo -e "Either rerun the script after installing curl, or"
            echo -e "Upload the file manually: 'copy & paste' to"
            nl
            echo -e "https://paste.ubuntu.com/"
            nl
        fi
    }
    
    
    ## MAIN ##
    Paster
    Explained:

    First checks the programs needed to do a Paste to a Pastebin, in order of preference. The first two, are not default installed to all flavors, but will paste to paste.ubuntu.com. The next two are default to all flavor's and will paste to termbin.com.

    On the paste, it uses the method related to the preferred program found.
    Last edited by MAFoElffen; September 9th, 2021 at 05:49 PM.

    "Concurrent coexistence of Windows, Linux and UNIX..." || Ubuntu user # 33563, Linux user # 533637
    Sticky: Graphics Resolution | UbuntuForums 'system-info' Script | Posting Guidelines | Code Tags

  2. #292
    Join Date
    Nov 2011
    Location
    /dev/root
    Beans
    Hidden!

    Re: Inspired

    @MAFoElffen,

    1. nc is in /bin in the versions 16.04 LTS and 18.04 LTS. But in 20.04 LTS and later it is in /usr/bin. So you should check for it also in /bin (which you do in the general system-info script (via type if I remember correctly).



    2. I tested the script in post #291, and had to edit it to make it work. Did you test it in a real computer before uploading?

    After some edits I managed to make 3 of 4 alternatives to upload the report file.

    I removed the tools one after another to make the script select the next one until all four were tested and I checked that there was a fair output suggesting manual uploading.

    Code:
    sudo mv /usr/bin/curl /usr/bin/curlx
    sudo mv /usr/bin/pastebinit /usr/bin/pastebinitx
    sudo mv /usr/bin/wget /usr/bin/wgetx
    sudo mv /usr/bin/nc /usr/bin/ncx
    Alternative 3 with wget failed. See this dialogue and the output created:

    Code:
    $ ./paste-test 
     Sensitive data is [REMOVED] from the report file 
    Do you want to upload the report file fo 'https://paste.ubuntu.com'? (y/N) y
    Uploading '/home/olle/system-info.txt' to 'https://paste.ubuntu.com'
    This may take 1-2 minutes...
    
    3
            |./paste-test: rad 74: varning: kommandoersättning: ignorerade nollbyte i indata
    - Upload successful 
    
    The link to the pastebin is saved in: '/home/sudodus/system-info-link.log'
    
    View the failed output at: https://termbin.com/kbpg
    My tweaks are attached as a patch file because it cannot be displayed between code tags.
    Attached Files Attached Files
    Last edited by sudodus; September 9th, 2021 at 01:14 PM. Reason: fixed missing code tag

  3. #293
    Join Date
    Mar 2010
    Location
    USA
    Beans
    Hidden!
    Distro
    Ubuntu Development Release

    Re: Inspired

    LOL. Works here. Will look at that.
    Code:
    mafoelffen@ubuntu:~/git/MAFoElffen1/system-info$ which wget
    /usr/bin/wget
    mafoelffen@ubuntu:~/git/MAFoElffen1/system-info$ wget --quiet -O- --post-data=$HOME/system-info 'termbin.com:9999'
    https://termbin.com/qepy
    mafoelffen@ubuntu:~/git/MAFoElffen1/system-info$ wget --quiet -O- --post-data=$HOME/system-info 'termbin.com:9999'
    https://termbin.com/e5hf
    I'll look in my emails, after I get the coffee going. <Caffeine. Stat.>

    "Concurrent coexistence of Windows, Linux and UNIX..." || Ubuntu user # 33563, Linux user # 533637
    Sticky: Graphics Resolution | UbuntuForums 'system-info' Script | Posting Guidelines | Code Tags

  4. #294
    Join Date
    Mar 2010
    Location
    USA
    Beans
    Hidden!
    Distro
    Ubuntu Development Release

    Re: Inspired

    Code:
    "command replacement: ignored zero bytes in input"
    So... It looks like if I " need to catch error messages from "termbin.com" to insure it "is" a successful paste or not. The command works in this locale.

    Can you try it at the command line and see please? It looks more like the script didn't find the file to send (said 0 bytes). Maybe it's complaining about spanning over several lines?
    Code:
    function PasteWget()
    {
        return_url=$(wget --quiet -O- --post-data=$report 'termbin.com:9999' )
        check_paste=$?
    }
    Another reason for wget preference over nc, because like curl, I can tune it for retries and timeouts, to allow for possible slow connections.
    Last edited by MAFoElffen; September 9th, 2021 at 05:55 PM.

    "Concurrent coexistence of Windows, Linux and UNIX..." || Ubuntu user # 33563, Linux user # 533637
    Sticky: Graphics Resolution | UbuntuForums 'system-info' Script | Posting Guidelines | Code Tags

  5. #295
    Join Date
    Mar 2010
    Location
    USA
    Beans
    Hidden!
    Distro
    Ubuntu Development Release

    Re: Inspired

    Did testing on the Paste options...

    Attached is the test script... At the end of the script was the outputs and URL's. And I confirmed the URL's that the system-info Reports were successfully posted at those URL's

    Like sudodus got as a script warning on this code I protoyped yesterday... When using wget and nc in a script, if I use variables for the report location, i get this warning
    Code:
    ./Paster4.sh: line XX: warning: command substitution: ignored null byte in input
    when it is doing the variable expansion... But it completes successfully. The Line Number corresponds to the line of the command. If I hard code it, it goes away.

    I think if I can somehow suppress that warning, somehow, then we are golden... But not sure "how" yet...

    It is a BASH script warning. Not stderr. Looking into that.


    EDIT:
    Success.

    The system-info.txt report is terminated with a \0 null character, and if calling cat from a script also opens another shell from within the script, so on those two,
    Code:
    return_url=$(wget --quiet -O- --post-data="$(tr -d '\0' <$report)" 'termbin.com:9999' )
    ## and...
    return_url=$(tr -d '\0' <$report | nc termbin.com 9999 )
    Read until the null character... That takes care of that... LOL
    Attached Files Attached Files
    Last edited by MAFoElffen; September 9th, 2021 at 10:32 PM.

    "Concurrent coexistence of Windows, Linux and UNIX..." || Ubuntu user # 33563, Linux user # 533637
    Sticky: Graphics Resolution | UbuntuForums 'system-info' Script | Posting Guidelines | Code Tags

  6. #296
    Join Date
    Nov 2011
    Location
    /dev/root
    Beans
    Hidden!

    Re: Inspired

    +1 I confirm that all 4 alternatives work now, but there are still complaints in my 18.04.5 LTS.

    I solved it this way by removing the null byte in another location. Does it solve it for you too @MAFoElffen?

    1. Your tweak: removing it when reading the report
    2. My tweak: removing it from the output of wget and nc

    Your tweak did not solve it for me. Will my tweak solve the problem for you? Or do we need both tweaks?

    Code:
    $ grep 'return_url.*termbin' Paster4.sh 
        return_url=$(wget --quiet -O- --post-data="`cat $report`" 'termbin.com:9999'  | tr '\0' '\n')
            return_url=$(cat $report | nc termbin.com 9999 | tr '\0' '\n')
    
    $ ./Paster4.sh 
    Menu to Test Paste.
    1 - Curl
    2 - Pastebinit
    3 - Wget
    4 - Nc
    5 - Quit
    Enter the number of the Test... 3
    Answer was: 3
    Passed 3
    Response: https://termbin.com/nuofv
    Exit code: 0
    Test was: 3   Response was: https://termbin.com/nuofv 
    
    Menu to Test Paste.
    1 - Curl
    2 - Pastebinit
    3 - Wget
    4 - Nc
    5 - Quit
    Enter the number of the Test... 4
    Answer was: 4
    Passed 4
    This uses a program which sometimes conflicts with 
    Anti-Virus Programs. You should turn that off if you 
    have installed.
    Would you like to proceed or skip? (y/N) y
    Response: https://termbin.com/gnz4
    Exit code: 0
    Test was: y   Response was: https://termbin.com/gnz4 
    
    Menu to Test Paste.
    1 - Curl
    2 - Pastebinit
    3 - Wget
    4 - Nc
    5 - Quit
    Enter the number of the Test... 5
    Answer was: 5
    Exiting Test...
    Last edited by sudodus; September 10th, 2021 at 01:38 AM. Reason: highlighting with colours

  7. #297
    Join Date
    Mar 2010
    Location
    USA
    Beans
    Hidden!
    Distro
    Ubuntu Development Release

    Re: Inspired

    Good that that works for 18.04 there. I Will mod it that way to be backward compatible for 18.04. I'll make sure that works here also.

    So is that how "everyone" wants Paster() to evolve into?

    If so, then I'll work to integrate that into the Master script....

    Edit: Still works here on two Live and 4 test VM's...
    Last edited by MAFoElffen; September 10th, 2021 at 03:39 AM.

    "Concurrent coexistence of Windows, Linux and UNIX..." || Ubuntu user # 33563, Linux user # 533637
    Sticky: Graphics Resolution | UbuntuForums 'system-info' Script | Posting Guidelines | Code Tags

  8. #298
    Join Date
    Nov 2011
    Location
    /dev/root
    Beans
    Hidden!

    Re: Inspired

    I tested it not only in 18.04 but also in a 20.04 server with the GA kernel

    Code:
    tester@ubuntu:~$ lsb_release -a
    No LSB modules are available.
    Distributor ID:	Ubuntu
    Description:	Ubuntu 20.04.3 LTS
    Release:	20.04
    Codename:	focal
    tester@ubuntu:~$ uname -r
    5.4.0-84-generic
    and 'my tweak' (without your tweak) works there too with all four uploading tools.

  9. #299
    Join Date
    Mar 2010
    Location
    USA
    Beans
    Hidden!
    Distro
    Ubuntu Development Release

    Re: Inspired

    @ sudodus.: LOL. Right... At least I do give credit where credit is due. I do have much patient, but... I am starting to feel a bit slighted and insulted... Do you mean to be doing that? Or is something else going on? I am a bit confused.

    I also tested it on Server with 5.11.1 and 5.14.2...
    Last edited by MAFoElffen; September 10th, 2021 at 04:01 AM.

    "Concurrent coexistence of Windows, Linux and UNIX..." || Ubuntu user # 33563, Linux user # 533637
    Sticky: Graphics Resolution | UbuntuForums 'system-info' Script | Posting Guidelines | Code Tags

  10. #300
    Join Date
    Mar 2010
    Location
    USA
    Beans
    Hidden!
    Distro
    Ubuntu Development Release

    Re: Inspired

    I'm sort of at a loss for words right now and I don't won't to say what I'm thinking right now...

    Here is current: https://raw.githubusercontent.com/Ma...in/system-info
    Code:
    mafoelffen@ubuntu:~/git/MAFoElffen1/system-info$ git add system-info
    
    mafoelffen@ubuntu:~/git/MAFoElffen1/system-info$ git commit -m "Integrated New Paster() function with alternate paste methods"
    [main 0777ce9] Integrated New Paster() function with alternate paste methods
     1 file changed, 171 insertions(+), 7 deletions(-)
    
    mafoelffen@ubuntu:~/git/MAFoElffen1/system-info$ git push
    Enumerating objects: 5, done.
    Counting objects: 100% (5/5), done.
    Delta compression using up to 4 threads
    Compressing objects: 100% (3/3), done.
    Writing objects: 100% (3/3), 1.38 KiB | 706.00 KiB/s, done.
    Total 3 (delta 2), reused 0 (delta 0)
    remote: Resolving deltas: 100% (2/2), completed with 2 local objects.
    remote: This repository moved. Please use the new location:
    remote:   https://github.com/Mafoelffen1/system-info.git
    To https://github.com/MAFoElffen1/system-info
       61c08bb..0777ce9  main -> main
    
    mafoelffen@ubuntu:~/git/MAFoElffen1/system-info$ date
    Thu Sep  9 20:36:30 PDT 2021

    "Concurrent coexistence of Windows, Linux and UNIX..." || Ubuntu user # 33563, Linux user # 533637
    Sticky: Graphics Resolution | UbuntuForums 'system-info' Script | Posting Guidelines | Code Tags

Page 30 of 98 FirstFirst ... 2028293031324080 ... LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •