Linux 操作系统脚本格式问题导致脚本无法执行

    最近,在做一个mysql的mgr+proxysql的集群初始化工作。在proxysql部署完成,开启proxysql的自动探测mysql集群运行状态时,proxysql后台日志报错提示:无法执行脚本,脚本文件或路径不存在,但是通过linux的命令ls -l查看报错的文件路径是正确的,见了鬼。无奈之下,手工运行脚本也报错命令或文件不存在:-bash: ./gr_sw_mode_checker.sh: /bin/bash^M: bad interpreter: No such file or directory。但是,看到了^M,太熟悉了,vi查看了下文件的格式,竟然是dos格式的,然后格式化成unix格式的,proxysql重于能调取到脚本,简直要泪奔的感觉。

    问题处理过程记录如下,以待后查:

    1、proxysql开启scheduler后,后台日志提示调取脚本失败

[root@mmgrpro1 proxysql]# tail -f proxysql.log 

2018-08-01 00:17:28 ProxySQL_Admin.cpp:7947:run_once(): [ERROR] Scheduler: Failed to run /var/lib/proxysql/gr_sw_mode_checker.sh

execve(): No such file or directory

2018-08-01 00:17:31 ProxySQL_Admin.cpp:7947:run_once(): [ERROR] Scheduler: Failed to run /var/lib/proxysql/gr_sw_mode_checker.sh

execve(): No such file or directory

2018-08-01 00:17:34 ProxySQL_Admin.cpp:7947:run_once(): [ERROR] Scheduler: Failed to run /var/lib/proxysql/gr_sw_mode_checker.sh

execve(): No such file or directory

    2、linux操作系统层查看脚本所在路径是否存在

[root@mmgrpro1 proxysql]# ls -l /var/lib/proxysql/gr_sw_mode_checker.sh

-rwxr-xr-x 1 mysql mysql 8292 Jul 31 15:47 /var/lib/proxysql/gr_sw_mode_checker.sh

[root@mmgrpro1 proxysql]#

到这,事情陷入僵局,脚本明明存在,但是proxysql却说找不到脚本。在此之前发生过,如果脚本没有执行权限时,

proxysql会报权限拒绝:

2018-07-31 16:57:39 ProxySQL_Admin.cpp:7947:run_once(): [ERROR] Scheduler: Failed to run /var/lib/proxysql/gr_sw_mode_checker.sh

execve(): Permission denied

2018-07-31 16:57:44 ProxySQL_Admin.cpp:7947:run_once(): [ERROR] Scheduler: Failed to run /var/lib/proxysql/gr_sw_mode_checker.sh

execve(): Permission denied

2018-07-31 16:57:48 MySQL_Monitor.cpp:1362:monitor_ping(): [ERROR] Server 192.168.10.131:3306 missed 3 heartbeats, shunning it and killing all the connections

2018-07-31 16:57:49 ProxySQL_Admin.cpp:7947:run_once(): [ERROR] Scheduler: Failed to run /var/lib/proxysql/gr_sw_mode_checker.sh

execve(): Permission denied

    3、自我反省,将实施方案看了无数变,又对照部署环境检查了好几遍,没发现任何异常,proxysql就是调取脚本失败,

实在是无奈呀,自己手工执行脚本,奇怪的是bash也报文件不存在:

[root@mmgrpro1 proxysql]# ./gr_sw_mode_checker.sh 

-bash: ./gr_sw_mode_checker.sh: /bin/bash^M : bad interpreter: No such file or directory

[root@mmgrpro1 proxysql]# ls -l /var/lib/proxysql/gr_sw_mode_checker.sh

-rwxr-xr-x 1 mysql mysql 8292 Jul 31 15:47 /var/lib/proxysql/gr_sw_mode_checker.sh

[root@mmgrpro1 proxysql]# 

但是,我看到了熟悉的面孔/bin/bash^M,终于找到了问题的症结,原本我是从网页上复制下来的脚本代码用UE编辑的,

脚本格式是DOS格式的,在unix或linux平台上需要转换成unix格式的。

    4、问题处理,使用vi编辑器,格式化脚本

--vi 脚本名称,输入shift+:,然后输入set ff?回车,查看脚本格式

--set ff?回车后显示是dos格式

--vi下,将脚本从dos转换成unix,输入set ff=unix回车,然后wq保存退出

    5、脚本保存后,proxysql调取脚本成功,虽然还有脚本相关的异常,但是不报:no such file or directory了

    到此问题解决,问题处理下来,真的不理解歪果仁的思维,明明是脚本内容有问题,却抛出个文件不存在的异常,让人费解。

猜你喜欢

转载自blog.csdn.net/www_xue_xi/article/details/81429652