Difference between revisions of "Script to Read Files"

From Observer GigaFlow Support | VIAVI Solutions Inc.
Jump to: navigation, search
 
(2 intermediate revisions by one user not shown)
Line 2: Line 2:
 
  var BufferedReader = Java.type('java.io.BufferedReader');
 
  var BufferedReader = Java.type('java.io.BufferedReader');
 
  var FileReader = Java.type('java.io.FileReader');
 
  var FileReader = Java.type('java.io.FileReader');
  var utils = Java.type('ros.CROSUtils');
+
var utils = Java.type('ros.CROSUtils');
 +
var now = new Date()
 
  log.warn("start")
 
  log.warn("start")
 +
var monthNames = ["Jan", "Feb", "Mar", "Apr", "May", "Jun",
 +
  "Jul", "Aug", "Sep", "Oct", "Nov", "Decr"
 +
];
 
  try {
 
  try {
var areader = objReader = new BufferedReader(new FileReader("/opt/ros/resources/webapps/static/syslog.txt"));
+
var areader = objReader = new BufferedReader(new FileReader("/opt/ros/resources/webapps/static/syslog.txt"));
 
var line = null;
 
var line = null;
 
while ((line = areader.readLine()) != null) {
 
while ((line = areader.readLine()) != null) {
//output.append(line);
+
      log.warn(line)
        log.warn(line)
+
        var thisone = line.split(" ");
        var thisone = line.split(" ");
+
      thisone[0]=monthNames[now.getMonth()]
      thisone[0]="test"
+
        thisone[1]=now.getDate()
      log.warn(thisone.join(" "))
+
        thisone[2]=now.getHours()+":"+now.getMinutes()+":"+now.getSeconds()
}
+
      log.warn(thisone.join(" "))
 +
}
 
  } catch ( e) {
 
  } catch ( e) {
    output.append(e.printStackTrace());
+
  areader.close()
 
  }
 
  }
 
  log.warn("end")
 
  log.warn("end")

Latest revision as of 13:17, 16 May 2022

var InputStreamReader= Java.type('java.io.InputStreamReader');
var BufferedReader = Java.type('java.io.BufferedReader');
var FileReader = Java.type('java.io.FileReader');
var utils = Java.type('ros.CROSUtils');
var now = new Date()
log.warn("start")
var monthNames = ["Jan", "Feb", "Mar", "Apr", "May", "Jun",
  "Jul", "Aug", "Sep", "Oct", "Nov", "Decr"
];
try {

var areader = objReader = new BufferedReader(new FileReader("/opt/ros/resources/webapps/static/syslog.txt")); var line = null; while ((line = areader.readLine()) != null) {

     	log.warn(line)
       var thisone = line.split(" ");	
     	thisone[0]=monthNames[now.getMonth()]
       thisone[1]=now.getDate()
       thisone[2]=now.getHours()+":"+now.getMinutes()+":"+now.getSeconds()
     	log.warn(thisone.join(" "))

}

} catch ( e) {
 areader.close()
}
log.warn("end")