This appears to have originated in the First World War, of which long, drawn-out trench warfare was a defining aspect, especially of the western front.
From a summary of Guy's Hospital Gazette (1914):
The best definition I have heard of modern warfare is, “Months of boredom punctuated by moments of extreme terror."
From a snippet of The New York Times Current History of the European War (1915):
Since then we have been doing infantry work in the trenches. We have been out of work on our trenches; only shrapnel and snipers. Some one described this war as "Months of boredom punctuated by moments of terror." It is sad that it is such a bad country for cavalry. Cavalry work here against far superior forces of infantry, like we had the other day, is not good enough.
The same phrase was used of the First World War such as The Fight for the Future (1916) by Edward Arthur Burroughs (Bishop of Repon)
"Months of boredom punctuated by moments of terror" : such is a description of life in the Navy which a naval lieutenant quotes as exactly fitting the facts. And one could quote many letters giving a similar impression of life in the Army, as it affects the type of man I have in mind, though here the ingredients are apt to be mingled in very different proportions, and the "moments of terror" may be ...
The same phrase, or variations thereof, have been used to describe wars in Algeria, Vietnam and Iraq, and often given as the definition of war, or at least war at the front.
Edward Bolland Osborn writes in The New Elizabethans: A First Selection of the Lives of Young Men who Have Fallen in the Great War (1919) of:
He takes great delight in the quaint sayings
of his men. For example, that of a weary person,
on whose face he had stepped while crawling to
his sleeping place in a lean-to behind a barn.
A weary voice muttered : " This is a blooming fine
game, played slow." And after a very long march
a trooper was heard saying to his very rough horse :
" You're no blooming Rolls-Royce, I give you my
word." He accepts somebody's definition of war
as utter boredom for many months, interspersed
with moments of acute terror -- "the boredom is
a fact," he adds.
Sentry-duty, with its moments of exaltation at
moon-rise or under a sky full of stars, was a
relief to what another New Elizabethan calls the
" organized boredom " of modern warfare ...
Later on he wrote, in a letter from the trenches, of the
" organized boredom " of modern warfare.
Julian Grenfell rather agreed with the definition of
the war as "months of boredom punctuated by
moments of terror." He loved the dangerous,
tumultuous life at the Front, but regretted the use-
lessness of cavalry there. "It is horrible" he
wrote, " having to leave one's horse. It feels like
leaving half oneself behind, and one feels the dual
responsibility all the same."
George A. Birmingham's A Padre in France (1918):
Some one described war at the front as an affair of months of boredom punctuated by moments of terror. If thst philosopher had been stationed at a base he might have halved his epigram and described war as months of boredom unpunctuated even by terror.
This is a serious problem for the military. A paper called Hours of Boredom, Moments of Terror Temporal Desynchrony in Military and Security Force Operations (Peter A. Hancock and Gerald P. Krueger, National Defense University, 2010, PDF) addresses this problem and concludes:
The “hurry up and wait” aspect of military operations, involving long periods of
boredom, has been around as long as warfare itself... It is intrinsic to all human warfare that periods of lassitude and inactivity frame the incidence of actual combat. ...
The notion of an automated and technological war might seem farfetched at present, and is far from the experience of combat troops on the ground. Thus, humans are still the central elements in current military and security-based operations, and the best policy for any commander or supervisor is to look after those human resources to the best of his/her ability. This means planning the temporal nature of the deployment experience is an important but as yet not fully resolved issue.