incomplete last line when writing to a file in java - java-io

I am writing to a file /etc/cron.d/myscript and using FileWriter/PrintWriter and flushing it before closing the writer but when I read the file using a vi editor , I get the status as incomplete last line.
FileWriter fw = new FileWriter(new File("/etc/cron.d/myscript"))
fw.write("#reboot username scriptpath");
fw.flush();
fw.close();
How can i avoid this , as it giving me problems in executing my cron job.
I've tried using PrintWriter as well but doesn't work.
I'm using java8 on Ubuntu 18.04

fw.write("#reboot username scriptpath"+"\n");
Solved the issue

Related

Internal Server Error with perl on Big Sur

I have a series of perl scripts I am unsing since many years. Now I want to modify one of them and copy the code into a new file with another name (modified with _n) It is in the same location and with the same permissions. Running it I get
Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
In the server log I read
End of script output before headers
I tried the same thing with other files that all work ok on my system, with the same result: Internal server error.
I also used a very simple script as
#!/usr/bin/perl
print "Content-type: text/html\n\n";
use strict;
use warnings;
print "Hello, world!<br />\n";
with the same result.
What is the difference that leads to this error?
MacOS Big Sur 11.2.3
Perl 5.34, reinstalled
BBEdit 14.0.1
Fetch 6.8.2
adding -w to the shebang solved the problem. Silly...

How to pass a variable via script to the terminal command line and ensure that it does not contain escape strings?

I am new to Ruby and most things related to the terminal. I am trying to make a script that would return information about RTP streams from a Wireshark trace file. I am implementing it in a way that simply creates a new trace file with only the packets that match the SSRC. Problem is when I pass the SSRC variable in the command that the script will execute I get an error saying that on line 1 the command "-w" was not found.
I don't quite understand what exactly is causing a new line to appear so it is hard for me to try anything really. I attempted to do some variatons of | sed 's///' but nothing I tried seemed to work.
My Ruby code;
stream = "0xb6143376"
`tshark -r #{file_name}.pcapng -d udp.port==#{src_port},rtp -2 -R
rtp.ssrc == #{stream} -w #{file_name}_stream1.pcapng`
Terminal output;
tshark: Syntax error.
sh: line 1: -w: command not found
So I expected the script to finish and at the end I would have a new trace file with only the packets that match 0xb6143376 SSRC. What I get instead is a new line right before -w
stream = stream.chomp
fixed my issue

RS command not found

I am doing a research on a number of subjects which requires that I submit my script to a supercomputer. My script was working fine on the individual subject, but I am getting this error when i submit it to the supercomputer.
rs command not found.
I am new to scripting but when i looked for this command in my terminal (type rs) it existed- but when i did the same in the supercomputer shell rs was not there.
Is there a way to download this specific command ?
THank you
Looks like your script does not include the details of $PATH variable when it gets executed.
To resolve this find the location of rs using which rs and include that location in the $PATH variable and export it inside the script. It would look something like this in your script:
export PATH=$PATH:`which rs`
NOTE: This might not work and you might have to replace the location of rs command explicitly instead of using it in a single command.
PS. Assuming you have rs extension installed in your system.

Log processing - send each new line in a log file as a parameter to script in real time

I have an active log file (which means there are new lines of log information appended to the file in real time).
What I want: When there is a new line appended, pass the new line of log as a parameter to a script (Bash, C, or even PHP).
What is better: instead of open a new process for every new line of log appended, run a demon process in the background to accept each line of new input.
I tried to Google, but haven't found any useful keyword to start.
By the way, it's running on Debian.
instead of open a new process for every new line of log appended, run
a demon process in the background to accept each line of new input.
tail -f log | demon&

Pig in grunt mode

I have installed cygwin, hadoop and pig in windows. The configuration seems ok, as I can run pig scripts in batch and embedded mode.
When I try to run pig in grunt mode, something strange happens. Let me explain.
I try to run a simple command like
grunt> A = load 'passwd' using PigStorage(':');
When I press Enter, nothing happens. The cursor goes to the next line and the grunt> prompt does not appear at all anymore. It seems as I am typing in a text editor.
Has anything similar ever happened to you? Do you have any idea how can I solve this?
The behavior is consistent with what you are observing. I will take the pig tutorial for example.
The following command does not result in any activity by pig.
raw = LOAD 'excite.log' USING PigStorage('\t') AS (user, time, query);
But if you invoke a command that results in using data from variable raw using some map-reduce thats when you will see some action in your grunt shell. Some thing along the lines of second command that is mentioned there.
clean1 = FILTER raw BY org.apache.pig.tutorial.NonURLDetector(query);
Similarly, your command will not result in any action, you have to use the data from variable A which results in map-reduce command to see some action on grunt shell:
grunt> A = load 'passwd' using PigStorage(':');
Pig will only process the commands when you use a command that creates output namely DUMP (to console) or STORE you can also use command DESCRIBE to get the structure of an alias and EXPLAIN to see the map/reduce plan
so basically DUMP A; will give you all the records in A
Please try to run in the windows command window.
C:\FAST\JDK64\1.6.0.31/bin/java -Xmx1000m -Dpig.log.dir=C:/cygwin/home/$USERNAME$/nubes/pig/logs -Dpig.log.file=pig.log -Dpig.home.dir=C:/cygwin/home/$USERNAME$/nubes/pig/ -classpath C:/cygwin/home/$USERNAME$/nubes/pig/conf;C;C:/FAST/JDK64/1.6.0.31/lib/tools.jar;C:/cygwin/home/$USERNAME$/nubes/pig/lib/jython-standalone-2.5.3.jar;C:/cygwin/home/$USERNAME$/nubes/pig/conf;C:/cygwin/home/$USERNAME$/nubes/hadoop/conf;C:/cygwin/home/$USERNAME$/nubes/pig/pig-0.11.1.jar org.apache.pig.Main -x local
Replace $USERNAME$ with your user id accordingly ..
Modify the class path and conf path accordingly ..
It works well in both local as well as map reduce mode ..
Pig shell hangs up in cygwin. But pig script successfully executed from pig script file.
As below:
$pig ./user/input.txt
For local mode:
pig -x local ./user/input.txt
I came across the same problem as you yesterday,and I spent one whole day to find what was wrong with my pig or my hotkey and fix it finally. I found that it's only because I copied the pig code from other resource,then the bending quotation marks cannot be identified in pig command line, which only admits straight quotation marks, so the input stream would not end.
My suggestion is that you should take care of the valid characters in the code, especially when you just copy codes into the command line, which always causes unexpected faults.

Resources