密码中的星号字符 - 登录失败

时间:2015-12-09 04:49:00

标签: linux bash shell scripting sftp

我有一个要求,我将sftp发送到不同的服务器,我想通过shell脚本执行此操作

但是密码有星号(*)字符,因此无法登录。 脚本:

public class Den1Fragment extends ListFragment {

private ProgressDialog pDialog;

// JSON Node names
private static final String TAG_CONTACTS = "contacts";
private static final String TAG_ID = "id";
private static final String TAG_NAME = "name";
private static final String TAG_EMAIL = "email";
private static final String TAG_ADDRESS = "address";
private static final String TAG_GENDER = "gender";
private static final String TAG_PHONE = "phone";
private static final String TAG_PHONE_MOBILE = "mobile";
private static final String TAG_PHONE_HOME = "home";
private static final String TAG_PHONE_OFFICE = "office";

// contacts JSONArray
private JSONArray contacts = null;

// Hashmap for ListView
private ArrayList<HashMap<String, String>> contactList = new ArrayList<>();;

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_den1, container, false);
ListView lv = getListView();

// Listview on item click listener
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {

    @Override
    public void onItemClick(AdapterView<?> parent, View view,
                            int position, long id) {
        // getting values from selected ListItem
        String name = ((TextView) view.findViewById(R.id.name))
                .getText().toString();
        String cost = ((TextView) view.findViewById(R.id.email))
                .getText().toString();
        String description = ((TextView) view.findViewById(R.id.mobile))
                .getText().toString();

        Intent in = new Intent(getActivity(), SingleContactActivity.class);
        in.putExtra(TAG_NAME, name);
        in.putExtra(TAG_EMAIL, cost);
        in.putExtra(TAG_PHONE_MOBILE, description);
        getActivity().startActivity(in); 

    }
});

// Calling async task to get json
new GetContacts().execute();

return view;
}

错误信息:

host=xxxxx
user=celcom_mnp
passwd='CjX3E$4Q&*B6L'
cd /home/mquser/unicaftp/CMS/batch/OBD/MNP/
test=`find . -maxdepth 1 -type f -name "*.csv" -mmin +1 | awk -F "/" '{print $NF}'`
lftp<<EOF
open sftp://$host
user  $user $passwd
cd /MNP_Autoin
lcd  /home/mquser/unicaftp/CMS/batch/OBD/MNP
mput `echo $test`
EOF
OUT=$?
if [ $OUT -eq 0 ];then
   echo "$test Succesfully transferred" >> /home/mquser/CIFM_STORE/OBD/obdmnplog.txt
else
   echo "Issue with sftp" >> /home/mquser/CIFM_STORE/CEP/PUSH/sftplog.txt
fi
mv $test /home/mquser/CIFM_STORE/OBD/TEMPMNP/

请帮帮我。提前致谢

2 个答案:

答案 0 :(得分:1)

尝试使用双引号而不是引号。 或者,如果您知道密码将始终是特定文本,则可以转义特殊字符$&amp; *用反斜杠加在前面。

您可以从谷歌尝试一些不同的解决方案: Unix Stack Exchange

答案 1 :(得分:1)

问题是&(&符号)。替换

user  $user $passwd

user  $user "$passwd"