Fórum Root.cz

Hlavní témata => Vývoj => Téma založeno: petrjah2 08. 08. 2012, 19:20:59

Název: Bash - base64: invalid input
Přispěvatel: petrjah2 08. 08. 2012, 19:20:59
Ahoj,

hraju si s bashem a pokouším převést kód do base64 a zpět.

Kód: (prevod.sh) [Vybrat]
#!/bin/bash

filesource=`cat "nejakykod.sh"`

myfce64encode=`echo "$filesource"|base64`
echo $myfce64encode > encode.sh

myfce64decode=`echo $myfce64encode | base64 -d`
echo $myfce64decode > decode.sh

exit 0;

Kód: (nejakykod.sh) [Vybrat]
#!/bin/bash

# Author: Duncan Phillips

# Guides followed:
# nagios guide - http://nagios.sourceforge.net/docs/3_0/quickstart-ubuntu.html
# merlin guide - https://wiki.op5.org/merlin:docs:quickstart-debian5
# ninja guide  - https://wiki.op5.org/ninja:docs:quickstart-ubuntu

# Run as root
[ "x$USER" != 'xroot' ] && echo "Please run as root." && exit 1

# Exit on error
set -e

cat << EOF

This script will attempt to install nagios/merlin/ninja/nagvis. It holds no guarentees!

WARNING: As part of the install, the script will install apache, mysql and a bunch of other stuff.
         It will also do some autoconfiguration which may wipe out settings you already have.
         It is strongly advised that you read through this script!

         Don't use on a production machine, rather run through the steps manually.

Please note the following usernames/password automatically setup. They should be changed:"
  - MySQL root/ no password"
  - System nagios/nagiosadmin"
  - htaccess /usr/local/nagios/etc/htpasswd.users nagiosadmin/nagiosadmin"

When the script has finished running, you will need to generate a self-signed certificate for apache ssl in /etc/ssl/. $
When loading the ninja interface for the first time, be sure to go to https://hostname/crossdomain.xml and add the secu$
the self signed certificate. This should be pretty self explanatory.

The geomap should give an error indicating that it needs a google maps api key. Just follow the link in the settings to$

Press <Enter> to kick off, Ctrl-C to cancel"

Bohužel vždy to skončí chybovou hláškou base64: invalid input.

Netušíte kde je zakopaný pes? Děkuji :-)
Název: Re:Bash - base64: invalid input
Přispěvatel: Lol Phirae 08. 08. 2012, 19:40:53
Kód: [Vybrat]
cat << EOF
No, dobrý, a kde je ten EOF?  :D
Název: Re:Bash - base64: invalid input
Přispěvatel: petrjah2 08. 08. 2012, 20:12:27
Kód: [Vybrat]
#!/bin/bash

# Author: Duncan Phillips

# Guides followed:
# nagios guide - http://nagios.sourceforge.net/docs/3_0/quickstart-ubuntu.html
# merlin guide - https://wiki.op5.org/merlin:docs:quickstart-debian5
# ninja guide  - https://wiki.op5.org/ninja:docs:quickstart-ubuntu

# Run as root
[ "x$USER" != 'xroot' ] && echo "Please run as root." && exit 1

# Exit on error
set -e

cat << EOF

This script will attempt to install nagios/merlin/ninja/nagvis. It holds no guarentees!

WARNING: As part of the install, the script will install apache, mysql and a bunch of other stuff.
         It will also do some autoconfiguration which may wipe out settings you already have.
         It is strongly advised that you read through this script!

         Don't use on a production machine, rather run through the steps manually.

Please note the following usernames/password automatically setup. They should be changed:"
  - MySQL root/ no password"
  - System nagios/nagiosadmin"
  - htaccess /usr/local/nagios/etc/htpasswd.users nagiosadmin/nagiosadmin"

When the script has finished running, you will need to generate a self-signed certificate for apache ssl in /etc/ssl/. Google is your friend.
When loading the ninja interface for the first time, be sure to go to https://hostname/crossdomain.xml and add the security exception for
the self signed certificate. This should be pretty self explanatory.

The geomap should give an error indicating that it needs a google maps api key. Just follow the link in the settings to get one (click the cog).

Press <Enter> to kick off, Ctrl-C to cancel"

EOF

Pardon, to mi vypadlo když jsem kopíroval kód. Jinak samozřejmě kód převádím i s EOF .
Název: Re:Bash - base64: invalid input
Přispěvatel: petrjah2 08. 08. 2012, 20:19:24
Lol Phirae Navíc nechápu proč by EOF podle tebe mělo mít na převod nějaký vliv ;-) To s tím přece nemá nic společného.
Název: Re:Bash - base64: invalid input
Přispěvatel: Lol Phirae 08. 08. 2012, 20:39:52
No, já zas pro změnu nechápu, co tam provádíš s tím echem apod.

Kód: [Vybrat]
base64 nejakykod.sh > encoded.sh
base64 -d encoded.sh > decoded.sh
Název: Re:Bash - base64: invalid input
Přispěvatel: petrjah2 08. 08. 2012, 20:45:35
Původně jsem si to tiskal do konzole. Teď už to ukládám do souboru.
Je sice pravda že to tam není třeba, ale ničemu to nevadí.

Pokud si kód převedu přes php, tak s tím není problém. http://www.shell-tools.net/index.php?op=base64_enc
Ale já to potřebuji udělat v Bashi.
Název: Re:Bash - base64: invalid input
Přispěvatel: Sten 08. 08. 2012, 21:14:54
Protože příkaz base64 tam vloží spoustu zalomení řádku, doporučuju ty proměnné dát do uvozovek
Název: Re:Bash - base64: invalid input
Přispěvatel: petrjah2 08. 08. 2012, 21:16:37
Lol Phirae Nakonec jsme to vyřešil, děkuji za navedení správnou cestou ;-)
Chyba byla opravdu v syntaxi.
Název: Re:Bash - base64: invalid input
Přispěvatel: Lol Phirae 08. 08. 2012, 21:21:11
Ano, chyba byla v chybějících uvozovkách, nicméně proč se učíš psát bash skripty jako prase, tomu fakt nerozumím. 4x zbytečné echo, 3 zbytečné proměnné, 2x zbytečná roura, 1x zbytečný cat.  ::)