scripting

How to search specific files from two folders and compare timestamp if the same or what is the newest files given using Batch Windows Scripting

江枫思渺然 提交于 2019-12-20 05:45:38
问题 I have initial code for searching and comparing in ALL files: SET FILE1=Directory1\* SET FILE2=Directory2\* FOR %%i IN (%FILE1%) DO SET DATE1=%%~ti FOR %%i IN (%FILE2%) DO SET DATE2=%%~ti IF "%DATE1%"=="%DATE2%" ECHO Files have same age && GOTO END FOR /F %%i IN ('DIR /B /O:D %FILE1% %FILE2%') DO SET NEWEST=%%i ECHO Newer file is %NEWEST% :END How do specifically search based on the directory that this certain file name should be search and compare? Sample: I want to search all specific like

Regular Expression to find string in Expect buffer

China☆狼群 提交于 2019-12-20 05:11:27
问题 I'm trying to find a regex that works to match a string of escape characters (an Expect response, see this question) and a six digit number (with alpha-numeric first character). Here's the whole string I need to identify: \r\n\u001b[1;14HX76196 Ultimately I need to extract the string: X76196 Here's what I have already: interact { #... #... #this expression does not identify the screen location #I need to find "\r\n\u001b[1;14H" AND "([a-zA-Z0-9]{1})[0-9]{5}$" #This regex was what I was using

Create a sudo user in script with no prompt for password, change to user without interrupting script

孤者浪人 提交于 2019-12-20 04:23:58
问题 This is what I'm trying to do in a script. It works here manually, but prompts me for a password. How do I: Create a new user With sudo privs Switch to that user Continue executing the rest of the script sudo adduser centos sudo passwd centos usermod -aG wheel centos sudo su centos I have tried the following but in Centos 7 bash, --disabled-password and -gecos both say "option not found." adduser --disabled-password --gecos "" username 回答1: You don't need sudo su centos because your script

Log read only at current date with error append to text file as output

。_饼干妹妹 提交于 2019-12-20 04:20:42
问题 I Have below text on remote computers (a list of 50 servers) saved in e:\logs\action.log This action.log will contain the a Date & time and every time a action performed will be tracked and appends the date & time..... and the next line will have the action associated like working, not working... Sample action.log file text..... [10/15/2012 09:33:56:248 qwe rtd] {some text will be there here} this time it is working on the task and taken: 2.31 seconds [10/15/2012 09:34:55:248 qwe rtd] {some

Replacing first occurence in every line

这一生的挚爱 提交于 2019-12-20 04:04:16
问题 Supposing I have a document formatted like this: word1 word2 word3 word4 word5 word6 word7 word8 How do I use sed to replace the first occurence of space with a comma followed by a space so that the document will look like: word1, word2 word3 word4, word5 word6 word7, word8 Thank you! 回答1: echo word1 word2 word3|sed -r 's/(\s)/,\1/' output: word1, word2 word3 回答2: Simple: sed -i 's/ /, /' your_file This looks for the first occurrence of a space, replaces it with a comma and space, then moves

Safari and Chrome doesn't evaluate dynamically added <script> tag at page load

佐手、 提交于 2019-12-20 03:48:04
问题 I am writing small JavaScript code which will load external js files at html page loading. I tested 2 ways. Case 1: Used document.write to add <script> tag. It worked for all browsers (IE, FF, Safari, Chrome, Opera). Case 2: Used DOMElement.appendChild to add <script> tag to the <haed> element. Only worked for IE, FF, and Opera. Did NOT work for Safari and Chrome. In both cases, I expected new <script> tag is being inserted before <head> closing tag. So the new <script> tag is evaluated

How to rename and add incrementing number suffix on multiple files in Batch Script?

强颜欢笑 提交于 2019-12-20 03:40:51
问题 I have 500 files coming in and I need to first check if any file(s) exist then rename all of them regardless of what their filename is (the files are named in a different language). No need to process them in any order. Rename: 1. “¦X¼d¬f-20110703-¦+¦dñHÑ-ª-¦=¬¦.xls” 2. “¦X¼d¬f-20110707-¦+¡¦-+¡8.xls” 3. “¦X¼d¬f-20110707-¦+¡¦ñj¦«.xls” 4. “¦X¼d¬f-20110708-¦+¡¦¬M¼n.xls” 5. “¦X¼d¬f-20110713-¦d¼O¼n¦hÑP.xls” . . . 500 To: “TWN_CH_INV_VISIT_FORM_01.xls” “TWN_CH_INV_VISIT_FORM_02.xls” “TWN_CH_INV

Unable to use wildcard for SSH command

北城以北 提交于 2019-12-20 03:28:12
问题 There are a number of files that I have to check if they exist in a directory. They follow a standard naming convention aside from the file extension so I want to use a wild card e.g: YYYYMM=201403 FILE_LIST=`cat config.txt` for file in $FILE_LIST do FILE=`echo $file | cut -f1 -d"~"` SEARCH_NAME=$FILE$YYYYMM ANSWER=`ssh -q userID@servername 'ls /home/to/some/directory/$SEARCH_NAME* | wc -l'` returnStatus=$? if [ $ANSWER=1 ]; then echo "FILE FOUND" else echo "FILE NOT FOUND" fi done The

initializing arrays in sh

旧时模样 提交于 2019-12-20 02:58:09
问题 I want to initialize an array in sh. In bash that would be: list=(`seq 1 4`) In sh I try to do it like this: for i in `seq 1 4`; do list[$((i-1))]="$i" done I get an error though for each iteration saying: list[0]=1: not found What am I doing wrong and how to fix that? 回答1: POSIX sh doesn't support arrays. You need a more advanced shell for that, e.g. bash , zsh , or ksh . 回答2: If you really want to use arrays, you can fudge them by writing your own array function. I'm not going to encourage

Storing a lua class with parent in luabind::object

谁说胖子不能爱 提交于 2019-12-20 02:45:27
问题 Using C++ , lua 5.1 , luabind 0.7-0.81 Trying to create a lua class with parent and store it in a luabind::object. Lua class 'TestClassParent' function TestClassParent:__init() print('parent init\n') end function TestClassParent:__finalize() print('parent finalize\n') end class 'TestClass' (TestClassParent) function TestClass:__init() print('init\n') TestClassParent.__init(self) end function TestClass:__finalize() print('finalize\n') end C++ { luabind::object obj = luabind::call_function