Bash and sh script help

Status
Not open for further replies.

NasKar

Guru
Joined
Jan 8, 2016
Messages
739
1) When using iocage console <jail> does that give the sh shell and not bash?
2) Most tutorials seem to give bash script as examples and I'm not sure how to translate to sh. Any sites that can help me learn how to convert or equivalent commands?
3) For example is the command shopt -s dotglob not available in sh?
 

NasKar

Guru
Joined
Jan 8, 2016
Messages
739
The default in FreeBSD is csh. If you want bash, you have to install it using pkg install bash.
When I run that command in my iocage jail it says it's already install. If I change the sheebang from #!/bin/sh to #/bin/bash I get an error saying bad interpreter.
 

danb35

Hall of Famer
Joined
Aug 16, 2011
Messages
15,504
I get an error saying bad interpreter.
@m0nkey_ has already given you the answer, but for future use, you could find it yourself by doing which bash. This will work for anything in your path.
 
Last edited:

NasKar

Guru
Joined
Jan 8, 2016
Messages
739
@m0nkey_ has already given you the answer, but for future use, you could find itself by doing which bash. This will work for anything in your path.
Code:
which bash
/usr/local/bin/bash

So if my jail is using bash why do I get the error
If I change the sheebang from #!/bin/sh to #/bin/bash I get an error saying bad interpreter

danb35 in your script for installing nextcloud why do you use the unix shebang #!/bin/sh instead of bash?
I've made a nextcloud backup and restore script that I was trying to get it to let you pick from a list the directory to restore from. Had to settle for passing the restore directory as a parameter when running the script. I did find bash script examples on the net but they wouldn't work with sh.
 

danb35

Hall of Famer
Joined
Aug 16, 2011
Messages
15,504
So if my jail is using bash why do I get the error
Because bash isn't in /bin/; it's in /usr/local/bin/, as the which command proved to you.
danb35 in your script for installing nextcloud why do you use the unix shebang #!/bin/sh instead of bash?
Because I don't need bash for my script.
 

NasKar

Guru
Joined
Jan 8, 2016
Messages
739
Because bash isn't in /bin/; it's in /usr/local/bin/, as the which command proved to you.
I'm sorry I was so dense. Thanks for clarifying it for me.

Do you have any idea if it is possible to restore a nextcloud backup that has a different database user and password than the current nextcloud database?
 

danb35

Hall of Famer
Joined
Aug 16, 2011
Messages
15,504
Do you have any idea if it is possible to restore a nextcloud backup that has a different database user and password than the current nextcloud database?
Idea? Yes. Certainty? No. I think it should be possible, as (IIRC) the database user and password are only stored in the Nextcloud config file, not in the Nextcloud database itself.
 

NasKar

Guru
Joined
Jan 8, 2016
Messages
739
FYI
Code:
Failed to connect to the database: An exception occured in driver: SQLSTATE[HY000] [1045] Access denied for user 'oldDB_user'@'localhost' (using password: YES) in /usr/local/www/nextcloud/lib/private/DB/Connection.php:64


I just reinstalled nextcloud with the old database username and pw and was able to restore the old DB to the new installation of nextcloud.
 

NasKar

Guru
Joined
Jan 8, 2016
Messages
739
the database user and password are only stored in the Nextcloud config file, not in the Nextcloud database itself.

After restoring the the nextcloud directory it copies over the config.php from the restore directory with the old username and password for the database. You then have to edit the config.php to change the dbuser and dbpassword back to the new install.

Any tips on what the sed command in a script would look like to substitute for example 'dbuser' => 'anydbuser', with 'dbuser' => 'originalUser' ? If originalUser is a variable $dbUser
It's much more complex that substituting yourip for 192.168.1.1 <G>.
 

danb35

Hall of Famer
Joined
Aug 16, 2011
Messages
15,504
Any tips on what the sed command in a script would look like to substitute for example 'dbuser' => 'anydbuser', with 'dbuser' => 'originalUser' ?
None at all. I wouldn't go that way; I'd look into a way of making the occ command work for me.
 

NasKar

Guru
Joined
Jan 8, 2016
Messages
739
Figured it out. Thanks
Code:
sed -i '' "s/'dbuser' => [^[:space:]]*/'dbuser' => '${dbUser}'/" /usr/local/www/nextcloud/config/config.php
 

NasKar

Guru
Joined
Jan 8, 2016
Messages
739
None at all. I wouldn't go that way; I'd look into a way of making the occ command work for me.
Do you think there is anything wrong with doing it with the sed command. I'm sure the occ command would have been easier.
 

danb35

Hall of Famer
Joined
Aug 16, 2011
Messages
15,504
Do you think there is anything wrong with doing it with the sed command.
I wouldn't think so--after all, it's perfectly valid to edit config.php by hand. But by using occ, you greatly reduce the chance of messing up the formatting.
 

NasKar

Guru
Joined
Jan 8, 2016
Messages
739
The sed command appears to work but get error using occ commands after doing that. So I'm trying to use the occ command. I can get the get command to work but not sure of the syntax for the setting a value.
su -m www -c 'php /usr/local/www/nextcloud/occ config:system:get dbuser'
Code:
su -m www -c 'php /usr/local/www/nextcloud/occ config:system:set dbuser .......'
 

danb35

Hall of Famer
Joined
Aug 16, 2011
Messages
15,504
The syntax for occ does seem pretty opaque. I have a number of examples of its use in my script; beyond that, the best I can suggest is the manual.
 

NasKar

Guru
Joined
Jan 8, 2016
Messages
739
I've check the manual and the list command to show all the commands. It hints at the use of the occ with the set option but doesn't spell it out. I'll keep digging. Thanks
 

danb35

Hall of Famer
Joined
Aug 16, 2011
Messages
15,504
Looking at the examples here (and what I'm doing in my script), it looks like the syntax would be occ config:system:set dbuser --value="newuser"
 

NasKar

Guru
Joined
Jan 8, 2016
Messages
739
Looking at the examples here (and what I'm doing in my script), it looks like the syntax would be occ config:system:set dbuser --value="newuser"
When I did
su -m www -c 'php /usr/local/www/nextcloud/occ config:system:set dbuser --value="newuser"' it worked but when I tried to change it back I get errors. Didn't realize it was because the db is broken with the wrong user name. Manually editing the config.php fixes it. I think that is what made me think the syntax was wrong.
 
Status
Not open for further replies.
Top