Using sed in terminal to replace text in file - sed

I have this text in this file:
test.php
$databases = array (
'default' =>
array (
'default' =>
array (
'database' => 'original',
'username' => 'root',
'password' => 'root',
'host' => 'localhost'
),
),
);
In terminal run this line to replace 'original' with 'new'
sed -i 's/original/new/g' test.php
UPDATE: The error message is:
sed: 1: "test.php": undefined label 'est.php'
What is the problem?
UPDATE 2:
If I just run: ( I removed '-i')
sed 's/original/new/g' test.php
I see the file text modified in the terminal. But then the file is not saved.

On BSDish platforms (including Mac OSX), the -i option requires an argument.
sed -i '' 's/original/new/g' test.php
Notice the empty argument ''.

Related

Magento 2 - SQLSTATE[42S02]: Base table or view not found when running a reindex

I am getting the following error on terminal when running bin/magento indexer:reindex:
***SQLSTATE[42S02]: Base table or view not found: 1146 Table 'catalog_product_index_price_cfg_opt_temp' doesn't exist, query was: DESCRIBE `catalog_product_index_price_cfg_opt_temp.
I have checked the website database and can confirm the table does exist but with no data.
catalog_product_index_price_cfg_opt_tmp table
When I manually run the SQL query (DESCRIBE `catalog_product_index_price_cfg_opt_temp) it created data.
However, when I try re-running the bin/magento indexer:reindex command following this, it removed the data created when running the above SQL command and i still get the same below error on terminal
***SQLSTATE[42S02]: Base table or view not found: 1146 Table 'catalog_product_index_price_cfg_opt_temp' doesn't exist, query was: DESCRIBE `catalog_product_index_price_cfg_opt_temp.
Hopefully you can help me to resolve this. Thank you!
Check if you are setting the table prefix correct in app/etc/env.php
...
'db' => [
'table_prefix' => 'pref_',
'connection' => [
'default' => [
'host' => 'localhost',
'dbname' => 'magentodb',
'username' => 'user',
'password' => 'pass',
'model' => 'mysql5',
'engine' => 'innodb',
'initStatements' => 'SET NAMES utf8;',
'active' => '1',
]
]
],
...
And do bin/magento indexer:reset

Add values between special chars using sed

I want to add respective values between '' for database, username etc.
$databases = array (
'default' =>
array (
'default' =>
array (
'database' => '',
'username' => '',
'password' => '',
'host' => '',
'port' => '',
'driver' => '',
'prefix' => '',
),
),
);
I already tried following, but didn't work.
sed -ie 's/'database' => ''/'database' => 'testdb'/g' file
Just like this (Using double quotes around your sed command:
sed -i "s/'database' => ''/'database' => 'testdb'/g" file
Or a better regex to handle 0 or more spaces:
sed -i "s/'database' *=> *''/'database' => 'testdb'/g" file
sed "/username/ s/''/'blabla'/" inputfile
This will search for the string username if it is matched then replace '' with 'blabla in the inputfile.
You can use sed -i.bak option to reflect changes in the file.

How to set GSSAPIAuthentication and GSSAPIDelegateCredentials attributes through CPAN module Net-OpenSSH

I am trying to create a ssh handle through module http://search.cpan.org/~salva/Net-OpenSSH-0.62/. I tried setting GSSAPIAuthentication and GSSAPIDelegateCredentials to "No", but these setting don't take effect if my .ssh/config is like this:
$ cat myusername/.ssh/config
Host *
CheckHostIP no
StrictHostKeyChecking no
HashKnownHosts no
GSSAPIAuthentication yes
GSSAPIDelegateCredentials no
UserKnownHostsFile /dev/null
LogLevel ERROR
This is how I try to set GSSAPIAuthentication and GSSAPIDelegateCredentials. Also is there a way to give -F option in open ssh constructor so that by default ssh uses some other config file rather than using the one user my user name?
$self->{ssh} = Net::OpenSSH->new($host,
user => $username,
passwd => $password,
timeout => $timeout,
default_stderr_discard => 1,
kill_ssh_on_timeout => 1,
master_opts => [-o => "UserKnownHostsFile=/dev/null",
-o => "GSSAPIAuthentication=no",
-o => "GSSAPIDelegateCredentials=no",
-o => "StrictHostKeyChecking=no"]);
Just add -F => 'somepath/config' under master_opts:
master_opts => [-F => 'somepath/config']
and another line like this:
$self->{ssh}->{_ssh_opts} = ['-F', 'somepath/config'];'

How to fix propect_lists subpanel in accounts, contacts and leads?

There is a description by Robert Lausegger (iscon group) which made it possible to show prospect list in a subpanel in other modules. But since SugarCRM 6.3 this wasn't working anymore.
How to fix this?
The site referenced in the above link was in German, so, courtesy of the author of that site, Robert Laussegger of the iscon group (www.iscongroup.net) in Germany, here is the english language version of the method. I used this on SugarCRM CE v 6.5 running on a LAMP stack with CentOS 6.4 base and it worked fine. Adjust to your install as appropriate.
The example given shows how to add a Target List (called Prospect List internally with SugarCRM) to a Contact DetailView; adjust the settings for Leads, ...
If the directories shown do not exist, create them, being careful to match not only spelling but capitalization. You will be adding 3 files in 3 separate directories.
Remember to set the file permissions and owner/group to allow the server to access the files created.
When finished adding the files and setting the permissions, as a CRM administrator, run:
Admin -> Repair -> Rebuild Relationships (to flush cache)
Admin -> Repair -> Quick Repair and Rebuild
Create the following files in the directories shown:
In /var/www/html//custom/Extension/modules/Contacts/Ext/Language
-Create file en_us.prospectlist_in_contacts_language.php
and into the file put
(the part of the filename " prospectlist_in_contacts_language" can be whatever you want, as long as you use the prefix "en_us." (for US English language) and the suffix ".php")
<?php
$mod_strings['LBL_PROSPECTLISTS_CONTACTS_FROM_PROSPECTLISTS_TITLE'] = 'Target Lists';
?>
In /var/www/html//custom/Extension/modules/Contacts/Ext/Layoutdefs
Create file prospectlist_in_contacts_layoutdef.php
and into the file put
(the part of the filename " prospectlist_in_contacts_layoutdef" can be whatever you want, as long as you use the suffix ".php")
<?php
$layout_defs["Contacts"]["subpanel_setup"]["prospect_list_contacts"] = array (
'order' => 100,
'module' => 'ProspectLists',
'subpanel_name' => 'default',
'sort_order' => 'asc',
'sort_by' => 'id',
'title_key' => 'LBL_PROSPECTLISTS_CONTACTS_FROM_PROSPECTLISTS_TITLE',
'get_subpanel_data' => 'prospect_list_contacts',
'top_buttons' =>
array (
0 =>
array (
'widget_class' => 'SubPanelTopButtonQuickCreate',
),
1 =>
array (
'widget_class' => 'SubPanelTopSelectButton',
'mode' => 'MultiSelect',
),
),
);
?>
In /var/www/html//custom/Extension/modules/Contacts/Ext/Vardefs
Create file prospectlist_in_contacts_vardef.php
and into the file put
(the part of the filename " prospectlist_in_contacts_vardef" can be whatever you want, as long as you use the suffix ".php")
<?php
$dictionary["Contact"]["fields"]["prospect_list_contacts"] = array (
'name' => 'prospect_list_contacts',
'type' => 'link',
'relationship' => 'prospect_list_contacts',
'source' => 'non-db',
'vname' => 'LBL_PROSPECTLISTS_CONTACTS_FROM_PROSPECTLISTS_TITLE',
);
$dictionary["Contact"]["fields"]["prospect_list_name"] = array (
'name' => 'prospect_list_name',
'rname' => 'name',
'id_name' => 'prospect_list_id',
'vname' => 'LBL_PROSPECTLISTS_CONTACTS_FROM_PROSPECTLISTS_TITLE',
'type' => 'relate',
'link' => 'prospect_lists',
'table' => 'prospect_lists',
'isnull' => 'true',
'module' => 'ProspectLists',
'dbType' => 'char',
'len' => '255',
'source' => 'non-db',
);
?>
Reset owner/permissions
Run, as CRM administrator
Admin -> Repair -> Rebuild Relationships (to flush cache)
Admin -> Repair -> Quick Repair and Rebuild
The vardefs have to be changed to:
$dictionary["Lead"]["fields"]["prospect_lists"] = array(
'name' => 'prospect_lists',
and the layoutdefs
'get_subpanel_data' => 'prospect_lists',
This solves the problem.

Cakephp Form Labels Encoding Utf8

In my php application since the beginning that i set everything with utf8 to avoid future problems. I set my database:
class DATABASE_CONFIG {
public $default = array(
'datasource' => 'Database/Mysql',
'persistent' => false,
'host' => 'localhost',
'login' => 'root',
'password' => '',
'database' => 'aquitex',
'prefix' => '',
'encoding' => 'utf8',
);
public $test = array(
'datasource' => 'Database/Mysql',
'persistent' => false,
'host' => 'localhost',
'login' => 'root',
'password' => '',
'database' => 'aquitex',
'prefix' => '',
'encoding' => 'utf8',
);
}
The file core.php:
Configure::write('App.encoding', 'UTF-8');
And the default layout of the views:
<?php echo $this->Html->charset(); ?>
However, i'm still having problems in some elements like labels of forms.
In my index.ctp file, this line:
echo $this->Html->link("Segurança", array('controller' => 'Posts','action'=> 'add'), array( 'class' => 'button'));
works perfectly and there's no problem with the 'ç' character.
But in forms, like this:
echo $this->Form->create('Post');
echo $this->Form->input('Nome Produto');
echo $this->Form->input(utf8_encode("Código Produto"));
echo $this->Form->input("Versão");
echo $this->Form->input('Data');
//echo $this->Form->input('body', array('rows' => '3'));
echo $this->Form->end('Criar Ficha');
there's no way i can get the words on the labels of the form with 'ó" or 'ç' characters showing properly. As you can see i even tried the utf8encode() in one of them.
Any hints? Thank you!
there is no need to use utf8_encode() in your views.
you simply forgot to save the view file properly.
save it as "utf8 without bom" and you will be fine.
files that do not contain any special utf8 char can still stay as ansi (since there is no difference between them then).
but every file that does contain such a character you need to save as utf8 (even controllers and models if you plan on using utf8 characters there for error messages etc).
PS: in general it is wiser to use english and to translate it via PO file into your language.
this way you can leave the files as they are and you are more flexible (you can add new languages on the fly just by creating a new PO file then).
EDIT
After figuring out together that your inputs() use utf8 chars, I will need to update:
It is wise to use "underscore_field_names" for your db fields (and therefore your input fields) - and in English:
echo $this->Form->input("version"));
you can easily translate them via PO file afterwards or specifying the label:
echo $this->Form->input("version", array('label' => 'Versão'));
but the first way is recommended to keep it dry.
App.encoding just tells Cake to send data in UTF8. If you're using MySQL, make sure the database itself is set to utf8_general_ci collation.